Jamie Hannaford | 3c1796b | 2015-02-12 14:21:33 +0100 | [diff] [blame] | 1 | package users |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | db "github.com/rackspace/gophercloud/openstack/db/v1/databases" |
| 7 | os "github.com/rackspace/gophercloud/openstack/db/v1/users" |
| 8 | "github.com/rackspace/gophercloud/pagination" |
| 9 | th "github.com/rackspace/gophercloud/testhelper" |
| 10 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 11 | ) |
| 12 | |
| 13 | const instanceID = "{instanceID}" |
| 14 | |
| 15 | func TestCreate(t *testing.T) { |
| 16 | th.SetupHTTP() |
| 17 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 18 | os.HandleCreate(t) |
Jamie Hannaford | 3c1796b | 2015-02-12 14:21:33 +0100 | [diff] [blame] | 19 | |
| 20 | opts := os.BatchCreateOpts{ |
| 21 | os.CreateOpts{ |
| 22 | Databases: db.BatchCreateOpts{ |
| 23 | db.CreateOpts{Name: "databaseA"}, |
| 24 | }, |
| 25 | Name: "dbuser3", |
| 26 | Password: "secretsecret", |
| 27 | }, |
| 28 | os.CreateOpts{ |
| 29 | Databases: db.BatchCreateOpts{ |
| 30 | db.CreateOpts{Name: "databaseB"}, |
| 31 | db.CreateOpts{Name: "databaseC"}, |
| 32 | }, |
| 33 | Name: "dbuser4", |
| 34 | Password: "secretsecret", |
| 35 | }, |
| 36 | } |
| 37 | |
| 38 | res := Create(fake.ServiceClient(), instanceID, opts) |
| 39 | th.AssertNoErr(t, res.Err) |
| 40 | } |
| 41 | |
| 42 | func TestUserList(t *testing.T) { |
| 43 | th.SetupHTTP() |
| 44 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 45 | os.HandleList(t) |
Jamie Hannaford | 3c1796b | 2015-02-12 14:21:33 +0100 | [diff] [blame] | 46 | |
| 47 | expectedUsers := []os.User{ |
| 48 | os.User{ |
| 49 | Databases: []db.Database{ |
| 50 | db.Database{Name: "databaseA"}, |
| 51 | }, |
| 52 | Name: "dbuser3", |
| 53 | }, |
| 54 | os.User{ |
| 55 | Databases: []db.Database{ |
| 56 | db.Database{Name: "databaseB"}, |
| 57 | db.Database{Name: "databaseC"}, |
| 58 | }, |
| 59 | Name: "dbuser4", |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | pages := 0 |
| 64 | err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) { |
| 65 | pages++ |
| 66 | |
| 67 | actual, err := os.ExtractUsers(page) |
| 68 | if err != nil { |
| 69 | return false, err |
| 70 | } |
| 71 | |
| 72 | th.CheckDeepEquals(t, expectedUsers, actual) |
| 73 | |
| 74 | return true, nil |
| 75 | }) |
| 76 | |
| 77 | th.AssertNoErr(t, err) |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 78 | th.AssertEquals(t, 1, pages) |
Jamie Hannaford | 3c1796b | 2015-02-12 14:21:33 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 81 | func TestDelete(t *testing.T) { |
Jamie Hannaford | 3c1796b | 2015-02-12 14:21:33 +0100 | [diff] [blame] | 82 | th.SetupHTTP() |
| 83 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 84 | os.HandleDelete(t) |
Jamie Hannaford | 3c1796b | 2015-02-12 14:21:33 +0100 | [diff] [blame] | 85 | |
| 86 | res := Delete(fake.ServiceClient(), instanceID, "{userName}") |
| 87 | th.AssertNoErr(t, res.Err) |
| 88 | } |