blob: 1ae07278cce307cb69a99453fb46bcd5ca6e184e [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"
Jon Perritt7e70c402014-10-24 16:15:09 -050010 "github.com/rackspace/gophercloud/acceptance/tools"
Jon Perritt8abd2c22014-10-16 20:28:51 -050011 "github.com/rackspace/gophercloud/rackspace"
12 th "github.com/rackspace/gophercloud/testhelper"
13)
14
15func rackspaceAuthOptions(t *testing.T) gophercloud.AuthOptions {
16 // Obtain credentials from the environment.
Ash Wilsona6ddde72014-10-22 15:26:42 -040017 options, err := rackspace.AuthOptionsFromEnv()
18 th.AssertNoErr(t, err)
19 options = tools.OnlyRS(options)
Jon Perritt8abd2c22014-10-16 20:28:51 -050020
21 if options.Username == "" {
22 t.Fatal("Please provide a Rackspace username as RS_USERNAME.")
23 }
24 if options.APIKey == "" {
Ash Wilsona6ddde72014-10-22 15:26:42 -040025 t.Fatal("Please provide a Rackspace API key as RS_API_KEY.")
Jon Perritt8abd2c22014-10-16 20:28:51 -050026 }
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}