Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v3 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Ash Wilson | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/openstack" |
| 9 | tokens3 "github.com/rackspace/gophercloud/openstack/identity/v3/tokens" |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func TestGetToken(t *testing.T) { |
| 13 | // Obtain credentials from the environment. |
Jamie Hannaford | 390555a | 2014-10-22 17:04:03 +0200 | [diff] [blame] | 14 | ao, err := openstack.AuthOptionsFromEnv() |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 15 | if err != nil { |
| 16 | t.Fatalf("Unable to acquire credentials: %v", err) |
| 17 | } |
| 18 | |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 19 | // Trim out unused fields. Skip if we don't have a UserID. |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 20 | ao.Username, ao.TenantID, ao.TenantName = "", "", "" |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 21 | if ao.UserID == "" { |
| 22 | t.Logf("Skipping identity v3 tests because no OS_USERID is present.") |
| 23 | return |
| 24 | } |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 25 | |
Ash Wilson | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame] | 26 | // Create an unauthenticated client. |
| 27 | provider, err := openstack.NewClient(ao.IdentityEndpoint) |
| 28 | if err != nil { |
| 29 | t.Fatalf("Unable to instantiate client: %v", err) |
| 30 | } |
| 31 | |
| 32 | // Create a service client. |
| 33 | service := openstack.NewIdentityV3(provider) |
| 34 | |
| 35 | // Use the service to create a token. |
Ash Wilson | 15f5b12 | 2014-10-02 09:54:54 -0400 | [diff] [blame] | 36 | token, err := tokens3.Create(service, ao, nil).Extract() |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 37 | if err != nil { |
| 38 | t.Fatalf("Unable to get token: %v", err) |
| 39 | } |
| 40 | |
Ash Wilson | 15f5b12 | 2014-10-02 09:54:54 -0400 | [diff] [blame] | 41 | t.Logf("Acquired token: %s", token.ID) |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 42 | } |