blob: 61ef4857a708afb6074ebe8fec173076b57afbbd [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
3package v1
4
5import (
Jamie Hannaford05d200d2015-02-20 14:49:05 +01006 "testing"
7
8 "github.com/rackspace/gophercloud"
Jamie Hannaford99eced52015-03-02 15:24:22 +01009 "github.com/rackspace/gophercloud/acceptance/tools"
Jamie Hannaford05d200d2015-02-20 14:49:05 +010010 "github.com/rackspace/gophercloud/rackspace"
Jamie Hannaford11108402015-02-23 10:31:41 +010011 "github.com/rackspace/gophercloud/rackspace/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 {
Jamie Hannaford99eced52015-03-02 15:24:22 +010016 opts, err := rackspace.AuthOptionsFromEnv()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010017 th.AssertNoErr(t, err)
Jamie Hannaford99eced52015-03-02 15:24:22 +010018 opts = tools.OnlyRS(opts)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010019
Jamie Hannaford99eced52015-03-02 15:24:22 +010020 client, err := rackspace.AuthenticatedClient(opts)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010021 th.AssertNoErr(t, err)
22
23 c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{
Jamie Hannaford99eced52015-03-02 15:24:22 +010024 Region: "IAD",
Jamie Hannaford05d200d2015-02-20 14:49:05 +010025 })
26 th.AssertNoErr(t, err)
27
28 return c
29}
30
31type 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 Hannaford11108402015-02-23 10:31:41 +010039 users []string
Jamie Hannaford05d200d2015-02-20 14:49:05 +010040}
41
42func newContext(t *testing.T) context {
43 return context{
44 test: t,
45 client: newClient(t),
46 }
47}
48
49func (c context) Logf(msg string, args ...interface{}) {
Jamie Hannaford99eced52015-03-02 15:24:22 +010050 if len(args) > 0 {
51 c.test.Logf(msg, args...)
52 } else {
53 c.test.Log(msg)
54 }
Jamie Hannaford05d200d2015-02-20 14:49:05 +010055}
56
57func (c context) AssertNoErr(err error) {
58 th.AssertNoErr(c.test, err)
59}
60
61func (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 Hannaford11108402015-02-23 10:31:41 +010072 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010073}