blob: 1bfad32f111e1505a1e8770b61686c8890b004d7 [file] [log] [blame]
Jamie Hannaford2a130242014-10-28 11:19:46 +01001package users
Jamie Hannaford929bd002014-10-29 11:14:25 +01002
3import (
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
11func 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}