| Jamie Hannaford | 2a13024 | 2014-10-28 11:19:46 +0100 | [diff] [blame] | 1 | package users | 
| Jamie Hannaford | 929bd00 | 2014-10-29 11:14:25 +0100 | [diff] [blame] | 2 |  | 
|  | 3 | import ( | 
|  | 4 | "testing" | 
|  | 5 |  | 
|  | 6 | "github.com/rackspace/gophercloud/pagination" | 
|  | 7 | th "github.com/rackspace/gophercloud/testhelper" | 
|  | 8 | "github.com/rackspace/gophercloud/testhelper/client" | 
|  | 9 | ) | 
|  | 10 |  | 
|  | 11 | func TestList(t *testing.T) { | 
|  | 12 | th.SetupHTTP() | 
|  | 13 | defer th.TeardownHTTP() | 
|  | 14 |  | 
|  | 15 | MockListResponse(t) | 
|  | 16 |  | 
|  | 17 | count := 0 | 
|  | 18 |  | 
|  | 19 | err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { | 
|  | 20 | count++ | 
|  | 21 | actual, err := ExtractUsers(page) | 
|  | 22 | if err != nil { | 
|  | 23 | t.Errorf("Failed to extract users: %v", err) | 
|  | 24 | return false, err | 
|  | 25 | } | 
|  | 26 |  | 
|  | 27 | expected := []User{ | 
|  | 28 | User{ | 
|  | 29 | ID:       "u1000", | 
|  | 30 | Name:     "John Smith", | 
|  | 31 | Username: "jqsmith", | 
|  | 32 | Email:    "john.smith@example.org", | 
|  | 33 | Enabled:  true, | 
|  | 34 | TenantID: "12345", | 
|  | 35 | }, | 
|  | 36 | User{ | 
|  | 37 | ID:       "u1001", | 
|  | 38 | Name:     "Jane Smith", | 
|  | 39 | Username: "jqsmith", | 
|  | 40 | Email:    "jane.smith@example.org", | 
|  | 41 | Enabled:  true, | 
|  | 42 | TenantID: "12345", | 
|  | 43 | }, | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | th.CheckDeepEquals(t, expected, actual) | 
|  | 47 |  | 
|  | 48 | return true, nil | 
|  | 49 | }) | 
|  | 50 |  | 
|  | 51 | th.AssertNoErr(t, err) | 
|  | 52 | th.AssertEquals(t, 1, count) | 
|  | 53 | } | 
| Jamie Hannaford | 9c7bb8e | 2014-10-29 11:47:34 +0100 | [diff] [blame^] | 54 |  | 
|  | 55 | func TestCreateUser(t *testing.T) { | 
|  | 56 | th.SetupHTTP() | 
|  | 57 | defer th.TeardownHTTP() | 
|  | 58 |  | 
|  | 59 | MockCreateUser(t) | 
|  | 60 |  | 
|  | 61 | opts := CreateOpts{ | 
|  | 62 | Name:     "new_user", | 
|  | 63 | TenantID: "12345", | 
|  | 64 | Enabled:  Disabled, | 
|  | 65 | Email:    "new_user@foo.com", | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | user, err := Create(client.ServiceClient(), opts).Extract() | 
|  | 69 |  | 
|  | 70 | th.AssertNoErr(t, err) | 
|  | 71 |  | 
|  | 72 | expected := &User{ | 
|  | 73 | Name:     "new_user", | 
|  | 74 | ID:       "c39e3de9be2d4c779f1dfd6abacc176d", | 
|  | 75 | Email:    "new_user@foo.com", | 
|  | 76 | Enabled:  false, | 
|  | 77 | TenantID: "12345", | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | th.AssertDeepEquals(t, expected, user) | 
|  | 81 | } |