Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame^] | 1 | // +build acceptance db |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 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 | |
| 14 | func 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 | |
| 29 | type context struct { |
| 30 | test *testing.T |
| 31 | client *gophercloud.ServiceClient |
| 32 | instanceID string |
| 33 | DBIDs []string |
| 34 | } |
| 35 | |
| 36 | func newContext(t *testing.T) context { |
| 37 | return context{ |
| 38 | test: t, |
| 39 | client: newClient(t), |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func (c context) Logf(msg string, args ...interface{}) { |
| 44 | c.test.Logf(msg, args) |
| 45 | } |
| 46 | |
| 47 | func (c context) AssertNoErr(err error) { |
| 48 | th.AssertNoErr(c.test, err) |
| 49 | } |
| 50 | |
| 51 | func (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 | } |