Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 1 | // +build acceptance db |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 6 | db "github.com/rackspace/gophercloud/openstack/db/v1/databases" |
| 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | ) |
| 9 | |
| 10 | func (c context) createDBs() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 11 | opts := db.BatchCreateOpts{ |
Jamie Hannaford | 3c3c784 | 2015-11-13 13:20:28 +0100 | [diff] [blame] | 12 | db.CreateOpts{Name: "db1"}, |
| 13 | db.CreateOpts{Name: "db2"}, |
| 14 | db.CreateOpts{Name: "db3"}, |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 15 | } |
| 16 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 17 | err := db.Create(c.client, c.instanceID, opts).ExtractErr() |
| 18 | c.AssertNoErr(err) |
Jamie Hannaford | 3c3c784 | 2015-11-13 13:20:28 +0100 | [diff] [blame] | 19 | c.Logf("Created three databases on instance %s: db1, db2, db3", c.instanceID) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | func (c context) listDBs() { |
| 23 | c.Logf("Listing databases on instance %s", c.instanceID) |
| 24 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 25 | 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] | 26 | dbList, err := db.ExtractDBs(page) |
| 27 | c.AssertNoErr(err) |
| 28 | |
| 29 | for _, db := range dbList { |
| 30 | c.Logf("DB: %#v", db) |
| 31 | } |
| 32 | |
| 33 | return true, nil |
| 34 | }) |
| 35 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 36 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | func (c context) deleteDBs() { |
Jamie Hannaford | 3c3c784 | 2015-11-13 13:20:28 +0100 | [diff] [blame] | 40 | for _, id := range []string{"db1", "db2", "db3"} { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 41 | err := db.Delete(c.client, c.instanceID, id).ExtractErr() |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 42 | c.AssertNoErr(err) |
| 43 | c.Logf("Deleted DB %s", id) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 44 | } |
| 45 | } |