Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 1 | // +build acceptance db |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud/acceptance/tools" |
| 7 | db "github.com/gophercloud/gophercloud/openstack/db/v1/databases" |
| 8 | u "github.com/gophercloud/gophercloud/openstack/db/v1/users" |
| 9 | "github.com/gophercloud/gophercloud/pagination" |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func (c context) createUsers() { |
| 13 | users := []string{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 14 | tools.RandomString("user_", 5), |
| 15 | tools.RandomString("user_", 5), |
| 16 | tools.RandomString("user_", 5), |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 17 | } |
| 18 | |
Jamie Hannaford | 3c3c784 | 2015-11-13 13:20:28 +0100 | [diff] [blame] | 19 | db1 := db.CreateOpts{Name: "db1"} |
| 20 | db2 := db.CreateOpts{Name: "db2"} |
| 21 | db3 := db.CreateOpts{Name: "db3"} |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 22 | |
| 23 | opts := u.BatchCreateOpts{ |
| 24 | u.CreateOpts{ |
| 25 | Name: users[0], |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 26 | Password: tools.RandomString("", 5), |
| 27 | Databases: db.BatchCreateOpts{db1, db2, db3}, |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 28 | }, |
| 29 | u.CreateOpts{ |
| 30 | Name: users[1], |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 31 | Password: tools.RandomString("", 5), |
| 32 | Databases: db.BatchCreateOpts{db1, db2}, |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 33 | }, |
| 34 | u.CreateOpts{ |
| 35 | Name: users[2], |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 36 | Password: tools.RandomString("", 5), |
| 37 | Databases: db.BatchCreateOpts{db3}, |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 38 | }, |
| 39 | } |
| 40 | |
| 41 | err := u.Create(c.client, c.instanceID, opts).ExtractErr() |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 42 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 43 | c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, users[0], users[1], users[2]) |
| 44 | c.users = users |
| 45 | } |
| 46 | |
| 47 | func (c context) listUsers() { |
| 48 | c.Logf("Listing databases on instance %s", c.instanceID) |
| 49 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 50 | 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] | 51 | dbList, err := db.ExtractDBs(page) |
| 52 | c.AssertNoErr(err) |
| 53 | |
| 54 | for _, db := range dbList { |
| 55 | c.Logf("DB: %#v", db) |
| 56 | } |
| 57 | |
| 58 | return true, nil |
| 59 | }) |
| 60 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 61 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | func (c context) deleteUsers() { |
| 65 | for _, id := range c.DBIDs { |
| 66 | err := db.Delete(c.client, c.instanceID, id).ExtractErr() |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 67 | c.AssertNoErr(err) |
| 68 | c.Logf("Deleted DB %s", id) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 69 | } |
| 70 | } |