blob: 642220380cca1bc09a903944f05683c90a62c86a [file] [log] [blame]
Jon Perritta77ba0d2014-10-17 01:15:29 -05001// +build acceptance rackspace objectstorage v1
Jon Perritt8abd2c22014-10-16 20:28:51 -05002
3package v1
4
5import (
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
14func 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
31func 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}