blob: 2665ce490e7ad64912aca160e31da87d96c4bec6 [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"
Jamie Hannaford11108402015-02-23 10:31:41 +010011 "github.com/rackspace/gophercloud/openstack/db/v1/instances"
Jamie Hannaford05d200d2015-02-20 14:49:05 +010012 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 := openstack.NewDBV1(client, gophercloud.EndpointOpts{
23 Region: os.Getenv("OS_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
Jamie Hannaford11108402015-02-23 10:31:41 +010035 users []string
Jamie Hannaford05d200d2015-02-20 14:49:05 +010036}
37
38func newContext(t *testing.T) context {
39 return context{
40 test: t,
41 client: newClient(t),
42 }
43}
44
45func (c context) Logf(msg string, args ...interface{}) {
46 c.test.Logf(msg, args)
47}
48
49func (c context) AssertNoErr(err error) {
50 th.AssertNoErr(c.test, err)
51}
52
53func (c context) WaitUntilActive(id string) {
54 err := gophercloud.WaitFor(60, func() (bool, error) {
55 inst, err := instances.Get(c.client, id).Extract()
56 if err != nil {
57 return false, err
58 }
59 if inst.Status == "ACTIVE" {
60 return true, nil
61 }
62 return false, nil
63 })
Jamie Hannaford11108402015-02-23 10:31:41 +010064
65 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010066}