blob: 293606b1e904fb52e5b99409c272c2f4ab8369c6 [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"
Ash Wilsondd7188d2014-09-05 14:02:42 -040010)
11
12func createAuthenticatedClient(t *testing.T) *gophercloud.ServiceClient {
13 // Obtain credentials from the environment.
Jamie Hannaford390555a2014-10-22 17:04:03 +020014 ao, err := openstack.AuthOptionsFromEnv()
Ash Wilsondd7188d2014-09-05 14:02:42 -040015 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 Wilson7083d022014-09-09 14:10:43 -040022 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 Wilsondd7188d2014-09-05 14:02:42 -040029 if err != nil {
30 t.Fatalf("Unable to instantiate client: %v", err)
31 }
32
Ash Wilson7083d022014-09-09 14:10:43 -040033 err = openstack.AuthenticateV3(providerClient, ao)
34 if err != nil {
35 t.Fatalf("Unable to authenticate against identity v3: %v", err)
36 }
37
Ash Wilsondd7188d2014-09-05 14:02:42 -040038 // Create a service client.
39 return openstack.NewIdentityV3(providerClient)
40}