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" |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/acceptance/tools" |
Ash Wilson | f4d6363 | 2014-10-09 14:54:06 -0400 | [diff] [blame] | 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. |
Ash Wilson | a6ddde7 | 2014-10-22 15:26:42 -0400 | [diff] [blame] | 16 | options, err := rackspace.AuthOptionsFromEnv() |
| 17 | th.AssertNoErr(t, err) |
| 18 | options = tools.OnlyRS(options) |
Ash Wilson | f4d6363 | 2014-10-09 14:54:06 -0400 | [diff] [blame] | 19 | |
| 20 | if options.Username == "" { |
| 21 | t.Fatal("Please provide a Rackspace username as RS_USERNAME.") |
| 22 | } |
| 23 | if options.APIKey == "" { |
Ash Wilson | a6ddde7 | 2014-10-22 15:26:42 -0400 | [diff] [blame] | 24 | t.Fatal("Please provide a Rackspace API key as RS_API_KEY.") |
Ash Wilson | f4d6363 | 2014-10-09 14:54:06 -0400 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | return options |
| 28 | } |
| 29 | |
| 30 | func 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 | |
| 44 | func unauthenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 45 | return createClient(t, false) |
| 46 | } |
| 47 | |
| 48 | func authenticatedClient(t *testing.T) *gophercloud.ServiceClient { |
| 49 | return createClient(t, true) |
| 50 | } |