blob: 576e40f53cd59b781941d517515ea3fded2cdd27 [file] [log] [blame]
Ash Wilsonf4d63632014-10-09 14:54:06 -04001// +build acceptance
2
3package v2
4
5import (
Ash Wilsonf4d63632014-10-09 14:54:06 -04006 "testing"
7
8 "github.com/rackspace/gophercloud"
9 "github.com/rackspace/gophercloud/rackspace"
10 th "github.com/rackspace/gophercloud/testhelper"
11)
12
13func rackspaceAuthOptions(t *testing.T) gophercloud.AuthOptions {
14 // Obtain credentials from the environment.
Ash Wilsona6ddde72014-10-22 15:26:42 -040015 options, err := rackspace.AuthOptionsFromEnv()
16 th.AssertNoErr(t, err)
17 options = tools.OnlyRS(options)
Ash Wilsonf4d63632014-10-09 14:54:06 -040018
19 if options.Username == "" {
20 t.Fatal("Please provide a Rackspace username as RS_USERNAME.")
21 }
22 if options.APIKey == "" {
Ash Wilsona6ddde72014-10-22 15:26:42 -040023 t.Fatal("Please provide a Rackspace API key as RS_API_KEY.")
Ash Wilsonf4d63632014-10-09 14:54:06 -040024 }
25
26 return options
27}
28
29func createClient(t *testing.T, auth bool) *gophercloud.ServiceClient {
30 ao := rackspaceAuthOptions(t)
31
32 provider, err := rackspace.NewClient(ao.IdentityEndpoint)
33 th.AssertNoErr(t, err)
34
35 if auth {
36 err = rackspace.Authenticate(provider, ao)
37 th.AssertNoErr(t, err)
38 }
39
40 return rackspace.NewIdentityV2(provider)
41}
42
43func unauthenticatedClient(t *testing.T) *gophercloud.ServiceClient {
44 return createClient(t, false)
45}
46
47func authenticatedClient(t *testing.T) *gophercloud.ServiceClient {
48 return createClient(t, true)
49}