Jamie Hannaford | 449c4ac | 2014-10-21 09:58:02 +0200 | [diff] [blame] | 1 | package volumes |
| 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("/volumes", 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 | "volumes": [ |
| 23 | { |
| 24 | "id": "289da7f8-6440-407c-9fb4-7db01ec49164", |
| 25 | "display_name": "vol-001" |
| 26 | }, |
| 27 | { |
| 28 | "id": "96c3bda7-c82a-4f50-be73-ca7621794835", |
| 29 | "display_name": "vol-002" |
| 30 | } |
| 31 | ] |
| 32 | } |
| 33 | `) |
| 34 | }) |
| 35 | } |
| 36 | |
| 37 | func MockGetResponse(t *testing.T) { |
| 38 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 39 | th.TestMethod(t, r, "GET") |
| 40 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 41 | |
| 42 | w.Header().Add("Content-Type", "application/json") |
| 43 | w.WriteHeader(http.StatusOK) |
| 44 | fmt.Fprintf(w, ` |
| 45 | { |
| 46 | "volume": { |
| 47 | "display_name": "vol-001", |
| 48 | "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22" |
| 49 | } |
| 50 | } |
| 51 | `) |
| 52 | }) |
| 53 | } |
| 54 | |
| 55 | func MockCreateResponse(t *testing.T) { |
| 56 | th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) { |
| 57 | th.TestMethod(t, r, "POST") |
| 58 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 59 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 60 | th.TestHeader(t, r, "Accept", "application/json") |
| 61 | th.TestJSONRequest(t, r, ` |
| 62 | { |
| 63 | "volume": { |
Jamie Hannaford | 59f2207 | 2014-10-23 17:00:59 +0200 | [diff] [blame] | 64 | "size": 75 |
Jamie Hannaford | 449c4ac | 2014-10-21 09:58:02 +0200 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | `) |
| 68 | |
| 69 | w.Header().Add("Content-Type", "application/json") |
| 70 | w.WriteHeader(http.StatusCreated) |
| 71 | |
| 72 | fmt.Fprintf(w, ` |
| 73 | { |
| 74 | "volume": { |
| 75 | "size": 4, |
| 76 | "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22" |
| 77 | } |
| 78 | } |
| 79 | `) |
| 80 | }) |
| 81 | } |
| 82 | |
| 83 | func MockDeleteResponse(t *testing.T) { |
| 84 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 85 | th.TestMethod(t, r, "DELETE") |
| 86 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 87 | w.WriteHeader(http.StatusNoContent) |
| 88 | }) |
| 89 | } |
| 90 | |
| 91 | func MockUpdateResponse(t *testing.T) { |
| 92 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 93 | th.TestMethod(t, r, "PUT") |
| 94 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 95 | w.WriteHeader(http.StatusOK) |
| 96 | fmt.Fprintf(w, ` |
| 97 | { |
| 98 | "volume": { |
| 99 | "display_name": "vol-002", |
| 100 | "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22" |
| 101 | } |
| 102 | } |
| 103 | `) |
| 104 | }) |
| 105 | } |