Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 1 | // +build acceptance db |
| 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 | |
| 11 | func (c context) createDBs() { |
| 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() |
| 25 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 26 | c.Logf("Created three databases on instance %s: %s, %s, %s", c.instanceID, dbs[0], dbs[1], dbs[2]) |
| 27 | c.DBIDs = dbs |
| 28 | } |
| 29 | |
| 30 | func (c context) listDBs() { |
| 31 | c.Logf("Listing databases on instance %s", c.instanceID) |
| 32 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 33 | 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] | 34 | dbList, err := db.ExtractDBs(page) |
| 35 | c.AssertNoErr(err) |
| 36 | |
| 37 | for _, db := range dbList { |
| 38 | c.Logf("DB: %#v", db) |
| 39 | } |
| 40 | |
| 41 | return true, nil |
| 42 | }) |
| 43 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 44 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | func (c context) deleteDBs() { |
| 48 | for _, id := range c.DBIDs { |
| 49 | err := db.Delete(c.client, c.instanceID, id).ExtractErr() |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 50 | c.AssertNoErr(err) |
| 51 | c.Logf("Deleted DB %s", id) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 52 | } |
| 53 | } |