blob: 2fd31753b6ffe305d9eb3ace833a6e91c73f085c [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
3package v1
4
5import (
Jamie Hannaford05d200d2015-02-20 14:49:05 +01006 db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
7 "github.com/rackspace/gophercloud/pagination"
8)
9
10func (c context) createDBs() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010011 opts := db.BatchCreateOpts{
Jamie Hannaford3c3c7842015-11-13 13:20:28 +010012 db.CreateOpts{Name: "db1"},
13 db.CreateOpts{Name: "db2"},
14 db.CreateOpts{Name: "db3"},
Jamie Hannaford05d200d2015-02-20 14:49:05 +010015 }
16
Jamie Hannaford11108402015-02-23 10:31:41 +010017 err := db.Create(c.client, c.instanceID, opts).ExtractErr()
18 c.AssertNoErr(err)
Jamie Hannaford3c3c7842015-11-13 13:20:28 +010019 c.Logf("Created three databases on instance %s: db1, db2, db3", c.instanceID)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010020}
21
22func (c context) listDBs() {
23 c.Logf("Listing databases on instance %s", c.instanceID)
24
Jamie Hannaford11108402015-02-23 10:31:41 +010025 err := db.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010026 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 Hannaford11108402015-02-23 10:31:41 +010036 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010037}
38
39func (c context) deleteDBs() {
Jamie Hannaford3c3c7842015-11-13 13:20:28 +010040 for _, id := range []string{"db1", "db2", "db3"} {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010041 err := db.Delete(c.client, c.instanceID, id).ExtractErr()
Jamie Hannaford11108402015-02-23 10:31:41 +010042 c.AssertNoErr(err)
43 c.Logf("Deleted DB %s", id)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010044 }
45}