Jamie Hannaford | 6e4d795 | 2014-10-29 16:18:29 +0100 | [diff] [blame] | 1 | package users |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | os "github.com/rackspace/gophercloud/openstack/identity/v2/users" |
| 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | func TestList(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
| 15 | |
| 16 | mockListResponse(t) |
| 17 | |
| 18 | count := 0 |
| 19 | |
| 20 | err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 21 | count++ |
| 22 | users, err := os.ExtractUsers(page) |
| 23 | |
| 24 | th.AssertNoErr(t, err) |
| 25 | th.AssertEquals(t, "u1000", users[0].ID) |
| 26 | th.AssertEquals(t, "u1001", users[1].ID) |
| 27 | |
| 28 | return true, nil |
| 29 | }) |
| 30 | |
| 31 | th.AssertNoErr(t, err) |
| 32 | th.AssertEquals(t, 1, count) |
| 33 | } |
| 34 | |
| 35 | func TestCreateUser(t *testing.T) { |
| 36 | th.SetupHTTP() |
| 37 | defer th.TeardownHTTP() |
| 38 | |
| 39 | mockCreateUser(t) |
| 40 | |
| 41 | opts := CreateOpts{ |
| 42 | Username: "new_user", |
| 43 | Enabled: os.Disabled, |
| 44 | Email: "new_user@foo.com", |
| 45 | Password: "foo", |
| 46 | } |
| 47 | |
| 48 | user, err := Create(client.ServiceClient(), opts).Extract() |
| 49 | |
| 50 | th.AssertNoErr(t, err) |
| 51 | |
| 52 | th.AssertEquals(t, "123456", user.ID) |
| 53 | th.AssertEquals(t, "5830280", user.DomainID) |
| 54 | th.AssertEquals(t, "DFW", user.DefaultRegion) |
| 55 | } |
| 56 | |
| 57 | func TestGetUser(t *testing.T) { |
| 58 | th.SetupHTTP() |
| 59 | defer th.TeardownHTTP() |
| 60 | |
| 61 | mockGetUser(t) |
| 62 | |
| 63 | user, err := Get(client.ServiceClient(), "new_user").Extract() |
| 64 | th.AssertNoErr(t, err) |
| 65 | |
| 66 | th.AssertEquals(t, true, user.Enabled) |
Jamie Hannaford | 14e44c9 | 2014-10-30 12:12:54 +0100 | [diff] [blame] | 67 | th.AssertEquals(t, true, user.MultiFactorEnabled) |
Jamie Hannaford | 6e4d795 | 2014-10-29 16:18:29 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | func TestUpdateUser(t *testing.T) { |
| 71 | th.SetupHTTP() |
| 72 | defer th.TeardownHTTP() |
| 73 | |
| 74 | mockUpdateUser(t) |
| 75 | |
| 76 | id := "c39e3de9be2d4c779f1dfd6abacc176d" |
| 77 | |
| 78 | opts := UpdateOpts{ |
| 79 | Enabled: os.Enabled, |
| 80 | Email: "new_email@foo.com", |
| 81 | } |
| 82 | |
| 83 | user, err := Update(client.ServiceClient(), id, opts).Extract() |
| 84 | |
| 85 | th.AssertNoErr(t, err) |
| 86 | |
| 87 | th.AssertEquals(t, true, user.Enabled) |
| 88 | th.AssertEquals(t, "new_email@foo.com", user.Email) |
| 89 | } |
| 90 | |
| 91 | func TestDeleteServer(t *testing.T) { |
| 92 | th.SetupHTTP() |
| 93 | defer th.TeardownHTTP() |
| 94 | |
| 95 | os.MockDeleteUser(t) |
| 96 | |
| 97 | res := Delete(client.ServiceClient(), "c39e3de9be2d4c779f1dfd6abacc176d") |
| 98 | th.AssertNoErr(t, res.Err) |
| 99 | } |