Ash Wilson | 8018c39 | 2014-10-03 14:35:56 -0400 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Ash Wilson | 8018c39 | 2014-10-03 14:35:56 -0400 | [diff] [blame] | 8 | tokens2 "github.com/rackspace/gophercloud/openstack/identity/v2/tokens" |
Ash Wilson | 8018c39 | 2014-10-03 14:35:56 -0400 | [diff] [blame] | 9 | th "github.com/rackspace/gophercloud/testhelper" |
| 10 | ) |
| 11 | |
| 12 | func TestAuthenticate(t *testing.T) { |
Ash Wilson | f4aee1e | 2014-10-03 15:25:13 -0400 | [diff] [blame^] | 13 | ao := v2AuthOptions(t) |
| 14 | service := unauthenticatedClient(t) |
Ash Wilson | 8018c39 | 2014-10-03 14:35:56 -0400 | [diff] [blame] | 15 | |
| 16 | // Authenticated! |
| 17 | result := tokens2.Create(service, ao) |
| 18 | |
| 19 | // Extract and print the token. |
| 20 | token, err := result.ExtractToken() |
| 21 | th.AssertNoErr(t, err) |
| 22 | |
| 23 | t.Logf("Acquired token: [%s]", token.ID) |
| 24 | t.Logf("The token will expire at: [%s]", token.ExpiresAt.String()) |
| 25 | t.Logf("The token is valid for tenant: [%#v]", token.Tenant) |
| 26 | |
| 27 | // Extract and print the service catalog. |
| 28 | catalog, err := result.ExtractServiceCatalog() |
| 29 | th.AssertNoErr(t, err) |
| 30 | |
| 31 | t.Logf("Acquired service catalog listing [%d] services", len(catalog.Entries)) |
| 32 | for i, entry := range catalog.Entries { |
Ash Wilson | f4aee1e | 2014-10-03 15:25:13 -0400 | [diff] [blame^] | 33 | t.Logf("[%02d]: name=[%s], type=[%s]", i, entry.Name, entry.Type) |
Ash Wilson | 8018c39 | 2014-10-03 14:35:56 -0400 | [diff] [blame] | 34 | for _, endpoint := range entry.Endpoints { |
| 35 | t.Logf(" - region=[%s] publicURL=[%s]", endpoint.Region, endpoint.PublicURL) |
| 36 | } |
| 37 | } |
| 38 | } |