Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame] | 1 | // +build fixtures |
| 2 | |
Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 3 | package roles |
| 4 | |
| 5 | import ( |
| 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 | |
| 14 | func MockListRoleResponse(t *testing.T) { |
Jamie Hannaford | 36a7dfd | 2014-10-30 14:31:34 +0100 | [diff] [blame] | 15 | th.Mux.HandleFunc("/OS-KSADM/roles", func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 16 | 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 | |
| 37 | func MockAddUserRoleResponse(t *testing.T) { |
Jamie Hannaford | b136b18 | 2014-10-30 15:20:10 +0100 | [diff] [blame] | 38 | th.Mux.HandleFunc("/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 39 | th.TestMethod(t, r, "PUT") |
| 40 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 41 | w.WriteHeader(http.StatusCreated) |
| 42 | }) |
| 43 | } |
| 44 | |
| 45 | func MockDeleteUserRoleResponse(t *testing.T) { |
Jamie Hannaford | b136b18 | 2014-10-30 15:20:10 +0100 | [diff] [blame] | 46 | th.Mux.HandleFunc("/users/{user_id}/roles/OS-KSADM/{role_id}", func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | d165fe7 | 2014-10-30 13:53:55 +0100 | [diff] [blame] | 47 | th.TestMethod(t, r, "DELETE") |
| 48 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 49 | w.WriteHeader(http.StatusNoContent) |
| 50 | }) |
| 51 | } |