Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 1 | // +build acceptance db |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 9 | "github.com/rackspace/gophercloud/acceptance/tools" |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 10 | "github.com/rackspace/gophercloud/rackspace" |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 11 | "github.com/rackspace/gophercloud/rackspace/db/v1/instances" |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
| 15 | func newClient(t *testing.T) *gophercloud.ServiceClient { |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 16 | opts, err := rackspace.AuthOptionsFromEnv() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 17 | th.AssertNoErr(t, err) |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 18 | opts = tools.OnlyRS(opts) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 19 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 20 | client, err := rackspace.AuthenticatedClient(opts) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 21 | th.AssertNoErr(t, err) |
| 22 | |
| 23 | c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{ |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 24 | Region: "IAD", |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 25 | }) |
| 26 | th.AssertNoErr(t, err) |
| 27 | |
| 28 | return c |
| 29 | } |
| 30 | |
| 31 | type context struct { |
| 32 | test *testing.T |
| 33 | client *gophercloud.ServiceClient |
| 34 | instanceID string |
| 35 | DBIDs []string |
| 36 | replicaID string |
| 37 | backupID string |
| 38 | configGroupID string |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 39 | users []string |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | func newContext(t *testing.T) context { |
| 43 | return context{ |
| 44 | test: t, |
| 45 | client: newClient(t), |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func (c context) Logf(msg string, args ...interface{}) { |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 50 | if len(args) > 0 { |
| 51 | c.test.Logf(msg, args...) |
| 52 | } else { |
| 53 | c.test.Log(msg) |
| 54 | } |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | func (c context) AssertNoErr(err error) { |
| 58 | th.AssertNoErr(c.test, err) |
| 59 | } |
| 60 | |
| 61 | func (c context) WaitUntilActive(id string) { |
| 62 | err := gophercloud.WaitFor(60, func() (bool, error) { |
| 63 | inst, err := instances.Get(c.client, id).Extract() |
| 64 | if err != nil { |
| 65 | return false, err |
| 66 | } |
| 67 | if inst.Status == "ACTIVE" { |
| 68 | return true, nil |
| 69 | } |
| 70 | return false, nil |
| 71 | }) |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 72 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 73 | } |