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 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud" |
| 9 | "github.com/gophercloud/gophercloud/openstack" |
| 10 | th "github.com/gophercloud/gophercloud/testhelper" |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func createAuthenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 14 | // Obtain credentials from the environment. |
Jamie Hannaford | 390555a | 2014-10-22 17:04:03 +0200 | [diff] [blame] | 15 | ao, err := openstack.AuthOptionsFromEnv() |
Ash Wilson | 4b33eea | 2014-10-22 15:45:45 -0400 | [diff] [blame] | 16 | th.AssertNoErr(t, err) |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 17 | |
| 18 | // Trim out unused fields. |
| 19 | ao.Username, ao.TenantID, ao.TenantName = "", "", "" |
| 20 | |
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 nil |
| 24 | } |
| 25 | |
| 26 | // Create a client and manually authenticate against v3. |
| 27 | providerClient, err := openstack.NewClient(ao.IdentityEndpoint) |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 28 | if err != nil { |
| 29 | t.Fatalf("Unable to instantiate client: %v", err) |
| 30 | } |
| 31 | |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 32 | err = openstack.AuthenticateV3(providerClient, ao) |
| 33 | if err != nil { |
| 34 | t.Fatalf("Unable to authenticate against identity v3: %v", err) |
| 35 | } |
| 36 | |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 37 | // Create a service client. |
| 38 | return openstack.NewIdentityV3(providerClient) |
| 39 | } |