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 | "github.com/rackspace/gophercloud/openstack/utils" |
| 11 | ) |
| 12 | |
| 13 | func TestGetToken(t *testing.T) { |
| 14 | // Obtain credentials from the environment. |
| 15 | ao, err := utils.AuthOptions() |
| 16 | if err != nil { |
| 17 | t.Fatalf("Unable to acquire credentials: %v", err) |
| 18 | } |
| 19 | |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 20 | // Trim out unused fields. Skip if we don't have a UserID. |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 21 | ao.Username, ao.TenantID, ao.TenantName = "", "", "" |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 22 | if ao.UserID == "" { |
| 23 | t.Logf("Skipping identity v3 tests because no OS_USERID is present.") |
| 24 | return |
| 25 | } |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 26 | |
Ash Wilson | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame] | 27 | // Create an unauthenticated client. |
| 28 | provider, err := openstack.NewClient(ao.IdentityEndpoint) |
| 29 | if err != nil { |
| 30 | t.Fatalf("Unable to instantiate client: %v", err) |
| 31 | } |
| 32 | |
| 33 | // Create a service client. |
| 34 | service := openstack.NewIdentityV3(provider) |
| 35 | |
| 36 | // Use the service to create a token. |
| 37 | result, err := tokens3.Create(service, ao, nil) |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 38 | if err != nil { |
| 39 | t.Fatalf("Unable to get token: %v", err) |
| 40 | } |
| 41 | |
Ash Wilson | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame] | 42 | token, err := result.TokenID() |
| 43 | if err != nil { |
| 44 | t.Fatalf("Unable to extract token from response: %v", err) |
| 45 | } |
| 46 | |
| 47 | t.Logf("Acquired token: %s", token) |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 48 | } |