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" |
| 10 | ) |
| 11 | |
| 12 | const instanceID = "{instanceID}" |
| 13 | |
| 14 | func TestCreate(t *testing.T) { |
| 15 | th.SetupHTTP() |
| 16 | defer th.TeardownHTTP() |
| 17 | |
| 18 | HandleCreateUserSuccessfully(t, instanceID) |
| 19 | |
| 20 | opts := BatchCreateOpts{ |
| 21 | CreateOpts{ |
| 22 | Databases: db.BatchCreateOpts{ |
| 23 | db.CreateOpts{Name: "databaseA"}, |
| 24 | }, |
| 25 | Name: "dbuser3", |
| 26 | Password: "secretsecret", |
| 27 | }, |
| 28 | 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() |
| 45 | |
| 46 | HandleListUsersSuccessfully(t, instanceID) |
| 47 | |
| 48 | expectedUsers := []User{ |
| 49 | User{ |
| 50 | Databases: []db.Database{ |
| 51 | db.Database{Name: "databaseA"}, |
| 52 | }, |
| 53 | Name: "dbuser3", |
| 54 | }, |
| 55 | User{ |
| 56 | Databases: []db.Database{ |
| 57 | db.Database{Name: "databaseB"}, |
| 58 | db.Database{Name: "databaseC"}, |
| 59 | }, |
| 60 | Name: "dbuser4", |
| 61 | }, |
| 62 | } |
| 63 | |
| 64 | pages := 0 |
| 65 | err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) { |
| 66 | pages++ |
| 67 | |
| 68 | actual, err := ExtractUsers(page) |
| 69 | if err != nil { |
| 70 | return false, err |
| 71 | } |
| 72 | |
| 73 | th.CheckDeepEquals(t, expectedUsers, actual) |
| 74 | |
| 75 | return true, nil |
| 76 | }) |
| 77 | |
| 78 | th.AssertNoErr(t, err) |
| 79 | |
| 80 | if pages != 1 { |
| 81 | t.Errorf("Expected 1 page, saw %d", pages) |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | func TestDeleteInstance(t *testing.T) { |
| 86 | th.SetupHTTP() |
| 87 | defer th.TeardownHTTP() |
| 88 | |
| 89 | HandleDeleteUserSuccessfully(t, instanceID, "{dbName}") |
| 90 | |
| 91 | res := Delete(fake.ServiceClient(), instanceID, "{dbName}") |
| 92 | th.AssertNoErr(t, res.Err) |
| 93 | } |