blob: 8256f0fe8e66531a5308d34ab010ee4d6d348716 [file] [log] [blame]
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01001package roles
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12func MockListRoleResponse(t *testing.T) {
Jamie Hannaford36a7dfd2014-10-30 14:31:34 +010013 th.Mux.HandleFunc("/OS-KSADM/roles", func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010014 th.TestMethod(t, r, "GET")
15 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
16
17 w.Header().Add("Content-Type", "application/json")
18 w.WriteHeader(http.StatusOK)
19
20 fmt.Fprintf(w, `
21{
22 "roles": [
23 {
24 "id": "123",
25 "name": "compute:admin",
26 "description": "Nova Administrator"
27 }
28 ]
29}
30 `)
31 })
32}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010033
34func MockAddUserRoleResponse(t *testing.T) {
Jamie Hannafordb136b182014-10-30 15:20:10 +010035 th.Mux.HandleFunc("/tenants/{tenant_id}/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford9b642e02014-10-30 13:20:06 +010036 th.TestMethod(t, r, "PUT")
37 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
38 w.WriteHeader(http.StatusCreated)
39 })
40}
Jamie Hannafordb15878a2014-10-30 13:26:32 +010041
42func MockDeleteUserRoleResponse(t *testing.T) {
Jamie Hannafordb136b182014-10-30 15:20:10 +010043 th.Mux.HandleFunc("/tenants/{tenant_id}/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) {
Jamie Hannafordb15878a2014-10-30 13:26:32 +010044 th.TestMethod(t, r, "DELETE")
45 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
46 w.WriteHeader(http.StatusNoContent)
47 })
48}