Jamie Hannaford | 80c7067 | 2015-10-06 16:09:33 +0200 | [diff] [blame] | 1 | // +build acceptance db rackspace |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "github.com/rackspace/gophercloud/acceptance/tools" |
| 7 | db "github.com/rackspace/gophercloud/openstack/db/v1/databases" |
| 8 | "github.com/rackspace/gophercloud/pagination" |
| 9 | ) |
| 10 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 11 | func (c *context) createDBs() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 12 | dbs := []string{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 13 | tools.RandomString("db_", 5), |
| 14 | tools.RandomString("db_", 5), |
| 15 | tools.RandomString("db_", 5), |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | opts := db.BatchCreateOpts{ |
| 19 | db.CreateOpts{Name: dbs[0]}, |
| 20 | db.CreateOpts{Name: dbs[1]}, |
| 21 | db.CreateOpts{Name: dbs[2]}, |
| 22 | } |
| 23 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 24 | err := db.Create(c.client, c.instanceID, opts).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 25 | c.Logf("Created three databases on instance %s: %s, %s, %s", c.instanceID, dbs[0], dbs[1], dbs[2]) |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 26 | c.AssertNoErr(err) |
| 27 | |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 28 | c.DBIDs = dbs |
| 29 | } |
| 30 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 31 | func (c *context) listDBs() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 32 | c.Logf("Listing databases on instance %s", c.instanceID) |
| 33 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 34 | err := db.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 35 | dbList, err := db.ExtractDBs(page) |
| 36 | c.AssertNoErr(err) |
| 37 | |
| 38 | for _, db := range dbList { |
| 39 | c.Logf("DB: %#v", db) |
| 40 | } |
| 41 | |
| 42 | return true, nil |
| 43 | }) |
| 44 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 45 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 46 | } |
| 47 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 48 | func (c *context) deleteDBs() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 49 | for _, id := range c.DBIDs { |
| 50 | err := db.Delete(c.client, c.instanceID, id).ExtractErr() |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 51 | c.AssertNoErr(err) |
| 52 | c.Logf("Deleted DB %s", id) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 53 | } |
| 54 | } |