blob: 1182982f44de1ba1778180b94d280d8fced3c5ed [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"
Jon Perritt7e70c402014-10-24 16:15:09 -05009 "github.com/rackspace/gophercloud/acceptance/tools"
Ash Wilsonf4d63632014-10-09 14:54:06 -040010 "github.com/rackspace/gophercloud/rackspace"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func rackspaceAuthOptions(t *testing.T) gophercloud.AuthOptions {
15 // Obtain credentials from the environment.
Ash Wilsona6ddde72014-10-22 15:26:42 -040016 options, err := rackspace.AuthOptionsFromEnv()
17 th.AssertNoErr(t, err)
18 options = tools.OnlyRS(options)
Ash Wilsonf4d63632014-10-09 14:54:06 -040019
20 if options.Username == "" {
21 t.Fatal("Please provide a Rackspace username as RS_USERNAME.")
22 }
23 if options.APIKey == "" {
Ash Wilsona6ddde72014-10-22 15:26:42 -040024 t.Fatal("Please provide a Rackspace API key as RS_API_KEY.")
Ash Wilsonf4d63632014-10-09 14:54:06 -040025 }
26
27 return options
28}
29
30func createClient(t *testing.T, auth bool) *gophercloud.ServiceClient {
31 ao := rackspaceAuthOptions(t)
32
33 provider, err := rackspace.NewClient(ao.IdentityEndpoint)
34 th.AssertNoErr(t, err)
35
36 if auth {
37 err = rackspace.Authenticate(provider, ao)
38 th.AssertNoErr(t, err)
39 }
40
41 return rackspace.NewIdentityV2(provider)
42}
43
44func unauthenticatedClient(t *testing.T) *gophercloud.ServiceClient {
45 return createClient(t, false)
46}
47
48func authenticatedClient(t *testing.T) *gophercloud.ServiceClient {
49 return createClient(t, true)
50}