blob: 019a9e6e4aeecdcff5b9b26ac8975b24e93a114b [file] [log] [blame]
Ash Wilsonf4d63632014-10-09 14:54:06 -04001// +build acceptance
2
3package v2
4
5import (
6 "os"
7 "testing"
8
9 "github.com/rackspace/gophercloud"
10 "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.
16 options := gophercloud.AuthOptions{
17 Username: os.Getenv("RS_USERNAME"),
18 APIKey: os.Getenv("RS_APIKEY"),
19 }
20
21 if options.Username == "" {
22 t.Fatal("Please provide a Rackspace username as RS_USERNAME.")
23 }
24 if options.APIKey == "" {
25 t.Fatal("Please provide a Rackspace API key as RS_APIKEY.")
26 }
27
28 return options
29}
30
31func createClient(t *testing.T, auth bool) *gophercloud.ServiceClient {
32 ao := rackspaceAuthOptions(t)
33
34 provider, err := rackspace.NewClient(ao.IdentityEndpoint)
35 th.AssertNoErr(t, err)
36
37 if auth {
38 err = rackspace.Authenticate(provider, ao)
39 th.AssertNoErr(t, err)
40 }
41
42 return rackspace.NewIdentityV2(provider)
43}
44
45func unauthenticatedClient(t *testing.T) *gophercloud.ServiceClient {
46 return createClient(t, false)
47}
48
49func authenticatedClient(t *testing.T) *gophercloud.ServiceClient {
50 return createClient(t, true)
51}