Ash Wilson | f4d6363 | 2014-10-09 14:54:06 -0400 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Ash Wilson | f4d6363 | 2014-10-09 14:54:06 -0400 | [diff] [blame] | 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | "github.com/rackspace/gophercloud/rackspace" |
| 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | ) |
| 12 | |
| 13 | func rackspaceAuthOptions(t *testing.T) gophercloud.AuthOptions { |
| 14 | // Obtain credentials from the environment. |
Ash Wilson | a6ddde7 | 2014-10-22 15:26:42 -0400 | [diff] [blame] | 15 | options, err := rackspace.AuthOptionsFromEnv() |
| 16 | th.AssertNoErr(t, err) |
| 17 | options = tools.OnlyRS(options) |
Ash Wilson | f4d6363 | 2014-10-09 14:54:06 -0400 | [diff] [blame] | 18 | |
| 19 | if options.Username == "" { |
| 20 | t.Fatal("Please provide a Rackspace username as RS_USERNAME.") |
| 21 | } |
| 22 | if options.APIKey == "" { |
Ash Wilson | a6ddde7 | 2014-10-22 15:26:42 -0400 | [diff] [blame] | 23 | t.Fatal("Please provide a Rackspace API key as RS_API_KEY.") |
Ash Wilson | f4d6363 | 2014-10-09 14:54:06 -0400 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | return options |
| 27 | } |
| 28 | |
| 29 | func 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 | |
| 43 | func unauthenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 44 | return createClient(t, false) |
| 45 | } |
| 46 | |
| 47 | func authenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 48 | return createClient(t, true) |
| 49 | } |