Jamie Hannaford | 2a13024 | 2014-10-28 11:19:46 +0100 | [diff] [blame] | 1 | package users |
Jamie Hannaford | 6a076d8 | 2014-10-29 10:57:36 +0100 | [diff] [blame] | 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 MockListResponse(t *testing.T) { |
| 13 | th.Mux.HandleFunc("/users", 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 | "users":[ |
| 23 | { |
| 24 | "id": "u1000", |
Jamie Hannaford | 929bd00 | 2014-10-29 11:14:25 +0100 | [diff] [blame] | 25 | "name": "John Smith", |
Jamie Hannaford | 6a076d8 | 2014-10-29 10:57:36 +0100 | [diff] [blame] | 26 | "username": "jqsmith", |
| 27 | "email": "john.smith@example.org", |
Jamie Hannaford | 929bd00 | 2014-10-29 11:14:25 +0100 | [diff] [blame] | 28 | "enabled": true, |
| 29 | "tenant_id": "12345" |
Jamie Hannaford | 6a076d8 | 2014-10-29 10:57:36 +0100 | [diff] [blame] | 30 | }, |
| 31 | { |
| 32 | "id": "u1001", |
Jamie Hannaford | 929bd00 | 2014-10-29 11:14:25 +0100 | [diff] [blame] | 33 | "name": "Jane Smith", |
Jamie Hannaford | 6a076d8 | 2014-10-29 10:57:36 +0100 | [diff] [blame] | 34 | "username": "jqsmith", |
Jamie Hannaford | 929bd00 | 2014-10-29 11:14:25 +0100 | [diff] [blame] | 35 | "email": "jane.smith@example.org", |
| 36 | "enabled": true, |
| 37 | "tenant_id": "12345" |
Jamie Hannaford | 6a076d8 | 2014-10-29 10:57:36 +0100 | [diff] [blame] | 38 | } |
| 39 | ] |
| 40 | } |
| 41 | `) |
| 42 | }) |
| 43 | } |
Jamie Hannaford | 9c7bb8e | 2014-10-29 11:47:34 +0100 | [diff] [blame] | 44 | |
| 45 | func MockCreateUser(t *testing.T) { |
| 46 | th.Mux.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) { |
| 47 | th.TestMethod(t, r, "POST") |
| 48 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 49 | |
| 50 | w.Header().Add("Content-Type", "application/json") |
| 51 | w.WriteHeader(http.StatusOK) |
| 52 | |
| 53 | fmt.Fprintf(w, ` |
| 54 | { |
| 55 | "user": { |
| 56 | "name": "new_user", |
| 57 | "tenant_id": "12345", |
| 58 | "enabled": false, |
| 59 | "email": "new_user@foo.com", |
| 60 | "id": "c39e3de9be2d4c779f1dfd6abacc176d" |
| 61 | } |
| 62 | } |
| 63 | `) |
| 64 | }) |
| 65 | } |
Jamie Hannaford | 2ad98bd | 2014-10-29 13:26:47 +0100 | [diff] [blame] | 66 | |
| 67 | func MockGetUser(t *testing.T) { |
| 68 | th.Mux.HandleFunc("/users/new_user", func(w http.ResponseWriter, r *http.Request) { |
| 69 | th.TestMethod(t, r, "GET") |
| 70 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 71 | |
| 72 | w.Header().Add("Content-Type", "application/json") |
| 73 | w.WriteHeader(http.StatusOK) |
| 74 | |
| 75 | fmt.Fprintf(w, ` |
| 76 | { |
| 77 | "user": { |
| 78 | "name": "new_user", |
| 79 | "tenant_id": "12345", |
| 80 | "enabled": false, |
| 81 | "email": "new_user@foo.com", |
| 82 | "id": "c39e3de9be2d4c779f1dfd6abacc176d" |
| 83 | } |
| 84 | } |
| 85 | `) |
| 86 | }) |
| 87 | } |