blob: fcee97d0bc3972640e6c7b3d02cc48b962ea7b9c [file] [log] [blame]
Jamie Hannafordd165fe72014-10-30 13:53:55 +01001package roles
2
3import (
4 "testing"
5
6 os "github.com/rackspace/gophercloud/openstack/identity/v2/extensions/admin/roles"
7 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12func TestRole(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15
16 MockListRoleResponse(t)
17
18 count := 0
19
20 err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
21 count++
22 actual, err := os.ExtractRoles(page)
23 if err != nil {
24 t.Errorf("Failed to extract users: %v", err)
25 return false, err
26 }
27
28 expected := []os.Role{
29 os.Role{
30 ID: "123",
31 Name: "compute:admin",
32 Description: "Nova Administrator",
33 ServiceID: "cke5372ebabeeabb70a0e702a4626977x4406e5",
34 },
35 }
36
37 th.CheckDeepEquals(t, expected, actual)
38
39 return true, nil
40 })
41
42 th.AssertNoErr(t, err)
43 th.AssertEquals(t, 1, count)
44}
45
46func TestAddUserRole(t *testing.T) {
47 th.SetupHTTP()
48 defer th.TeardownHTTP()
49
50 MockAddUserRoleResponse(t)
51
52 err := AddUserRole(client.ServiceClient(), "{user_id}", "{role_id}").ExtractErr()
53
54 th.AssertNoErr(t, err)
55}
56
57func TestDeleteUserRole(t *testing.T) {
58 th.SetupHTTP()
59 defer th.TeardownHTTP()
60
61 MockDeleteUserRoleResponse(t)
62
63 err := DeleteUserRole(client.ServiceClient(), "{user_id}", "{role_id}").ExtractErr()
64
65 th.AssertNoErr(t, err)
66}