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