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" |
| 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, 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 | } |