Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 1 | package roles |
| 2 | |
| 3 | import ( |
| 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 | |
| 12 | func MockListRoleResponse(t *testing.T) { |
Jamie Hannaford | 36a7dfd | 2014-10-30 14:31:34 +0100 | [diff] [blame] | 13 | th.Mux.HandleFunc("/OS-KSADM/roles", func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 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 | } |
| 28 | ] |
| 29 | } |
| 30 | `) |
| 31 | }) |
| 32 | } |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 33 | |
| 34 | func MockAddUserRoleResponse(t *testing.T) { |
Jamie Hannaford | b136b18 | 2014-10-30 15:20:10 +0100 | [diff] [blame] | 35 | th.Mux.HandleFunc("/tenants/{tenant_id}/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 36 | th.TestMethod(t, r, "PUT") |
| 37 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 38 | w.WriteHeader(http.StatusCreated) |
| 39 | }) |
| 40 | } |
Jamie Hannaford | b15878a | 2014-10-30 13:26:32 +0100 | [diff] [blame] | 41 | |
| 42 | func MockDeleteUserRoleResponse(t *testing.T) { |
Jamie Hannaford | b136b18 | 2014-10-30 15:20:10 +0100 | [diff] [blame] | 43 | th.Mux.HandleFunc("/tenants/{tenant_id}/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | b15878a | 2014-10-30 13:26:32 +0100 | [diff] [blame] | 44 | th.TestMethod(t, r, "DELETE") |
| 45 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 46 | w.WriteHeader(http.StatusNoContent) |
| 47 | }) |
| 48 | } |