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 | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame^] | 20 | // Trim out unused fields. |
| 21 | ao.TenantID, ao.TenantName = "", "" |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 22 | |
Ash Wilson | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame^] | 23 | // Create an unauthenticated client. |
| 24 | provider, err := openstack.NewClient(ao.IdentityEndpoint) |
| 25 | if err != nil { |
| 26 | t.Fatalf("Unable to instantiate client: %v", err) |
| 27 | } |
| 28 | |
| 29 | // Create a service client. |
| 30 | service := openstack.NewIdentityV3(provider) |
| 31 | |
| 32 | // Use the service to create a token. |
| 33 | result, err := tokens3.Create(service, ao, nil) |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 34 | if err != nil { |
| 35 | t.Fatalf("Unable to get token: %v", err) |
| 36 | } |
| 37 | |
Ash Wilson | 9d9fb10 | 2014-09-03 11:26:31 -0400 | [diff] [blame^] | 38 | token, err := result.TokenID() |
| 39 | if err != nil { |
| 40 | t.Fatalf("Unable to extract token from response: %v", err) |
| 41 | } |
| 42 | |
| 43 | t.Logf("Acquired token: %s", token) |
Ash Wilson | 4215691 | 2014-09-02 14:08:22 -0400 | [diff] [blame] | 44 | } |