blob: cbfbf58bdc1457293b363e2996205883376fb70e [file] [log] [blame]
Jamie Hannafordd165fe72014-10-30 13:53:55 +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) {
13 th.Mux.HandleFunc("/OS-KSADMN/roles", func(w http.ResponseWriter, r *http.Request) {
14 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 "serviceId": "cke5372ebabeeabb70a0e702a4626977x4406e5"
28 }
29 ]
30}
31 `)
32 })
33}
34
35func MockAddUserRoleResponse(t *testing.T) {
36 th.Mux.HandleFunc("/users/{user_id}/OS-KSADMN/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
37 th.TestMethod(t, r, "PUT")
38 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
39 w.WriteHeader(http.StatusCreated)
40 })
41}
42
43func MockDeleteUserRoleResponse(t *testing.T) {
44 th.Mux.HandleFunc("/users/{user_id}/OS-KSADMN/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
45 th.TestMethod(t, r, "DELETE")
46 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
47 w.WriteHeader(http.StatusNoContent)
48 })
49}