Ash Wilson | f4d6363 | 2014-10-09 14:54:06 -0400 | [diff] [blame^] | 1 | // +build acceptance |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 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 | |
| 14 | func 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 | |
| 31 | func 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 | |
| 45 | func unauthenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 46 | return createClient(t, false) |
| 47 | } |
| 48 | |
| 49 | func authenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 50 | return createClient(t, true) |
| 51 | } |