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" |
| 10 | "github.com/rackspace/gophercloud/openstack/utils" |
| 11 | ) |
| 12 | |
| 13 | func createAuthenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 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 | |
| 20 | // Trim out unused fields. |
| 21 | ao.Username, ao.TenantID, ao.TenantName = "", "", "" |
| 22 | |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 23 | if ao.UserID == "" { |
| 24 | t.Logf("Skipping identity v3 tests because no OS_USERID is present.") |
| 25 | return nil |
| 26 | } |
| 27 | |
| 28 | // Create a client and manually authenticate against v3. |
| 29 | providerClient, err := openstack.NewClient(ao.IdentityEndpoint) |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 30 | if err != nil { |
| 31 | t.Fatalf("Unable to instantiate client: %v", err) |
| 32 | } |
| 33 | |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 34 | err = openstack.AuthenticateV3(providerClient, ao) |
| 35 | if err != nil { |
| 36 | t.Fatalf("Unable to authenticate against identity v3: %v", err) |
| 37 | } |
| 38 | |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 39 | // Create a service client. |
| 40 | return openstack.NewIdentityV3(providerClient) |
| 41 | } |