blob: e194e3142397f1c6a0625a62d4c60b6535267115 [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannafordd165fe72014-10-30 13:53:55 +01003package roles
4
5import (
6 "fmt"
7 "net/http"
8 "testing"
9
10 th "github.com/rackspace/gophercloud/testhelper"
11 fake "github.com/rackspace/gophercloud/testhelper/client"
12)
13
14func MockListRoleResponse(t *testing.T) {
Jamie Hannaford36a7dfd2014-10-30 14:31:34 +010015 th.Mux.HandleFunc("/OS-KSADM/roles", func(w http.ResponseWriter, r *http.Request) {
Jamie Hannafordd165fe72014-10-30 13:53:55 +010016 th.TestMethod(t, r, "GET")
17 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
18
19 w.Header().Add("Content-Type", "application/json")
20 w.WriteHeader(http.StatusOK)
21
22 fmt.Fprintf(w, `
23{
24 "roles": [
25 {
26 "id": "123",
27 "name": "compute:admin",
28 "description": "Nova Administrator",
29 "serviceId": "cke5372ebabeeabb70a0e702a4626977x4406e5"
30 }
31 ]
32}
33 `)
34 })
35}
36
37func MockAddUserRoleResponse(t *testing.T) {
Jamie Hannafordb136b182014-10-30 15:20:10 +010038 th.Mux.HandleFunc("/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) {
Jamie Hannafordd165fe72014-10-30 13:53:55 +010039 th.TestMethod(t, r, "PUT")
40 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
41 w.WriteHeader(http.StatusCreated)
42 })
43}
44
45func MockDeleteUserRoleResponse(t *testing.T) {
Jamie Hannafordb136b182014-10-30 15:20:10 +010046 th.Mux.HandleFunc("/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) {
Jamie Hannafordd165fe72014-10-30 13:53:55 +010047 th.TestMethod(t, r, "DELETE")
48 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
49 w.WriteHeader(http.StatusNoContent)
50 })
51}