blob: e2d41cf189fc3152467ee94dd9ef452645d2ca6e [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
3package v1
4
5import (
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
11func (c context) createDBs() {
12 dbs := []string{
13 tools.RandomString("db_"),
14 tools.RandomString("db_"),
15 tools.RandomString("db_"),
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
24 res := db.Create(c.client, c.instanceID, opts)
25 c.Logf("Created three databases on instance %s: %s, %s, %s", c.instanceID, dbs[0], dbs[1], dbs[2])
26 c.DBIDs = dbs
27}
28
29func (c context) listDBs() {
30 c.Logf("Listing databases on instance %s", c.instanceID)
31
32 err := dbs.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
33 dbList, err := db.ExtractDBs(page)
34 c.AssertNoErr(err)
35
36 for _, db := range dbList {
37 c.Logf("DB: %#v", db)
38 }
39
40 return true, nil
41 })
42
43 c.CheckNoErr(err)
44}
45
46func (c context) deleteDBs() {
47 for _, id := range c.DBIDs {
48 err := db.Delete(c.client, c.instanceID, id).ExtractErr()
49 c.CheckNoErr(err)
50 t.Logf("Deleted DB %s", id)
51 }
52}