blob: 2fa977fb1f69749c16bbd4dad4c586538b52cd69 [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
3package v1
4
5import (
6 "os"
7 "testing"
8
9 "github.com/rackspace/gophercloud"
10 "github.com/rackspace/gophercloud/openstack"
11 "github.com/rackspace/gophercloud/rackspace"
12 th "github.com/rackspace/gophercloud/testhelper"
13)
14
15func newClient(t *testing.T) *gophercloud.ServiceClient {
16 ao, err := openstack.AuthOptionsFromEnv()
17 th.AssertNoErr(t, err)
18
19 client, err := openstack.AuthenticatedClient(ao)
20 th.AssertNoErr(t, err)
21
22 c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{
23 Region: os.Getenv("RS_REGION_NAME"),
24 })
25 th.AssertNoErr(t, err)
26
27 return c
28}
29
30type context struct {
31 test *testing.T
32 client *gophercloud.ServiceClient
33 instanceID string
34 DBIDs []string
35 replicaID string
36 backupID string
37 configGroupID string
38}
39
40func newContext(t *testing.T) context {
41 return context{
42 test: t,
43 client: newClient(t),
44 }
45}
46
47func (c context) Logf(msg string, args ...interface{}) {
48 c.test.Logf(msg, args)
49}
50
51func (c context) AssertNoErr(err error) {
52 th.AssertNoErr(c.test, err)
53}
54
55func (c context) WaitUntilActive(id string) {
56 err := gophercloud.WaitFor(60, func() (bool, error) {
57 inst, err := instances.Get(c.client, id).Extract()
58 if err != nil {
59 return false, err
60 }
61 if inst.Status == "ACTIVE" {
62 return true, nil
63 }
64 return false, nil
65 })
66}