blob: e0503e233e7315f8d5c1e8fb1ff069b32efc7f4a [file] [log] [blame]
Ash Wilson739a6cc2014-10-03 14:36:14 -04001// +build acceptance
2
Ash Wilsondd7188d2014-09-05 14:02:42 -04003package v3
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 "github.com/rackspace/gophercloud/openstack"
10 "github.com/rackspace/gophercloud/openstack/utils"
11)
12
13func 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 Wilson7083d022014-09-09 14:10:43 -040023 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 Wilsondd7188d2014-09-05 14:02:42 -040030 if err != nil {
31 t.Fatalf("Unable to instantiate client: %v", err)
32 }
33
Ash Wilson7083d022014-09-09 14:10:43 -040034 err = openstack.AuthenticateV3(providerClient, ao)
35 if err != nil {
36 t.Fatalf("Unable to authenticate against identity v3: %v", err)
37 }
38
Ash Wilsondd7188d2014-09-05 14:02:42 -040039 // Create a service client.
40 return openstack.NewIdentityV3(providerClient)
41}