Jon Perritt | a77ba0d | 2014-10-17 01:15:29 -0500 | [diff] [blame] | 1 | // +build acceptance rackspace objectstorage v1 |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/rackspace/gophercloud" |
Jon Perritt | 7e70c40 | 2014-10-24 16:15:09 -0500 | [diff] [blame] | 10 | "github.com/rackspace/gophercloud/acceptance/tools" |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 11 | "github.com/rackspace/gophercloud/rackspace" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
| 15 | func rackspaceAuthOptions(t *testing.T) gophercloud.AuthOptions { |
| 16 | // Obtain credentials from the environment. |
Ash Wilson | a6ddde7 | 2014-10-22 15:26:42 -0400 | [diff] [blame] | 17 | options, err := rackspace.AuthOptionsFromEnv() |
| 18 | th.AssertNoErr(t, err) |
| 19 | options = tools.OnlyRS(options) |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 20 | |
| 21 | if options.Username == "" { |
| 22 | t.Fatal("Please provide a Rackspace username as RS_USERNAME.") |
| 23 | } |
| 24 | if options.APIKey == "" { |
Ash Wilson | a6ddde7 | 2014-10-22 15:26:42 -0400 | [diff] [blame] | 25 | t.Fatal("Please provide a Rackspace API key as RS_API_KEY.") |
Jon Perritt | 8abd2c2 | 2014-10-16 20:28:51 -0500 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | return options |
| 29 | } |
| 30 | |
| 31 | func createClient(t *testing.T, cdn bool) (*gophercloud.ServiceClient, error) { |
| 32 | region := os.Getenv("RS_REGION") |
| 33 | if region == "" { |
| 34 | t.Fatal("Please provide a Rackspace region as RS_REGION") |
| 35 | } |
| 36 | |
| 37 | ao := rackspaceAuthOptions(t) |
| 38 | |
| 39 | provider, err := rackspace.NewClient(ao.IdentityEndpoint) |
| 40 | th.AssertNoErr(t, err) |
| 41 | |
| 42 | err = rackspace.Authenticate(provider, ao) |
| 43 | th.AssertNoErr(t, err) |
| 44 | |
| 45 | if cdn { |
| 46 | return rackspace.NewObjectCDNV1(provider, gophercloud.EndpointOpts{ |
| 47 | Region: region, |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | return rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{ |
| 52 | Region: region, |
| 53 | }) |
| 54 | } |