Ash Wilson | 739a6cc | 2014-10-03 14:36:14 -0400 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 3 | package v3 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | "github.com/rackspace/gophercloud/openstack" |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func createAuthenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 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 | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 15 | if err != nil { |
| 16 | t.Fatalf("Unable to acquire credentials: %v", err) |
| 17 | } |
| 18 | |
| 19 | // Trim out unused fields. |
| 20 | ao.Username, ao.TenantID, ao.TenantName = "", "", "" |
| 21 | |
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 nil |
| 25 | } |
| 26 | |
| 27 | // Create a client and manually authenticate against v3. |
| 28 | providerClient, err := openstack.NewClient(ao.IdentityEndpoint) |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 29 | if err != nil { |
| 30 | t.Fatalf("Unable to instantiate client: %v", err) |
| 31 | } |
| 32 | |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 33 | err = openstack.AuthenticateV3(providerClient, ao) |
| 34 | if err != nil { |
| 35 | t.Fatalf("Unable to authenticate against identity v3: %v", err) |
| 36 | } |
| 37 | |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 38 | // Create a service client. |
| 39 | return openstack.NewIdentityV3(providerClient) |
| 40 | } |