blob: 88bfecca508526ee4bdc7afe9996798e49080938 [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannaford0ca076c2014-10-30 13:12:35 +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 Hannaford0ca076c2014-10-30 13:12:35 +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 }
30 ]
31}
32 `)
33 })
34}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010035
36func MockAddUserRoleResponse(t *testing.T) {
Jamie Hannafordb136b182014-10-30 15:20:10 +010037 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 +010038 th.TestMethod(t, r, "PUT")
39 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
40 w.WriteHeader(http.StatusCreated)
41 })
42}
Jamie Hannafordb15878a2014-10-30 13:26:32 +010043
44func MockDeleteUserRoleResponse(t *testing.T) {
Jamie Hannafordb136b182014-10-30 15:20:10 +010045 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 +010046 th.TestMethod(t, r, "DELETE")
47 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
48 w.WriteHeader(http.StatusNoContent)
49 })
50}