blob: 6974ad072ddce05f1aea07529a061a58c63dca7c [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
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud"
9 "github.com/gophercloud/gophercloud/openstack"
10 th "github.com/gophercloud/gophercloud/testhelper"
Ash Wilsondd7188d2014-09-05 14:02:42 -040011)
12
13func createAuthenticatedClient(t *testing.T) *gophercloud.ServiceClient {
14 // Obtain credentials from the environment.
Jamie Hannaford390555a2014-10-22 17:04:03 +020015 ao, err := openstack.AuthOptionsFromEnv()
Ash Wilson4b33eea2014-10-22 15:45:45 -040016 th.AssertNoErr(t, err)
Ash Wilsondd7188d2014-09-05 14:02:42 -040017
18 // Trim out unused fields.
19 ao.Username, ao.TenantID, ao.TenantName = "", "", ""
20
Ash Wilson7083d022014-09-09 14:10:43 -040021 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 Wilsondd7188d2014-09-05 14:02:42 -040028 if err != nil {
29 t.Fatalf("Unable to instantiate client: %v", err)
30 }
31
Ash Wilson7083d022014-09-09 14:10:43 -040032 err = openstack.AuthenticateV3(providerClient, ao)
33 if err != nil {
34 t.Fatalf("Unable to authenticate against identity v3: %v", err)
35 }
36
Ash Wilsondd7188d2014-09-05 14:02:42 -040037 // Create a service client.
38 return openstack.NewIdentityV3(providerClient)
39}