blob: 13d7628ac0538133203dc0a5a82a30391e47bdf0 [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 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func newClient(t *testing.T) *gophercloud.ServiceClient {
15 ao, err := openstack.AuthOptionsFromEnv()
16 th.AssertNoErr(t, err)
17
18 client, err := openstack.AuthenticatedClient(ao)
19 th.AssertNoErr(t, err)
20
21 c, err := openstack.NewDBV1(client, gophercloud.EndpointOpts{
22 Region: os.Getenv("OS_REGION_NAME"),
23 })
24 th.AssertNoErr(t, err)
25
26 return c
27}
28
29type context struct {
30 test *testing.T
31 client *gophercloud.ServiceClient
32 instanceID string
33 DBIDs []string
34}
35
36func newContext(t *testing.T) context {
37 return context{
38 test: t,
39 client: newClient(t),
40 }
41}
42
43func (c context) Logf(msg string, args ...interface{}) {
44 c.test.Logf(msg, args)
45}
46
47func (c context) AssertNoErr(err error) {
48 th.AssertNoErr(c.test, err)
49}
50
51func (c context) WaitUntilActive(id string) {
52 err := gophercloud.WaitFor(60, func() (bool, error) {
53 inst, err := instances.Get(c.client, id).Extract()
54 if err != nil {
55 return false, err
56 }
57 if inst.Status == "ACTIVE" {
58 return true, nil
59 }
60 return false, nil
61 })
62}