Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame^] | 1 | // +build fixtures |
| 2 | |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 3 | package testing |
Jamie Hannaford | 449c4ac | 2014-10-21 09:58:02 +0200 | [diff] [blame] | 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 MockListResponse(t *testing.T) { |
| 15 | th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) { |
| 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 | "volumes": [ |
| 25 | { |
| 26 | "id": "289da7f8-6440-407c-9fb4-7db01ec49164", |
| 27 | "display_name": "vol-001" |
| 28 | }, |
| 29 | { |
| 30 | "id": "96c3bda7-c82a-4f50-be73-ca7621794835", |
| 31 | "display_name": "vol-002" |
| 32 | } |
| 33 | ] |
| 34 | } |
| 35 | `) |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | func MockGetResponse(t *testing.T) { |
| 40 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 41 | th.TestMethod(t, r, "GET") |
| 42 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 43 | |
| 44 | w.Header().Add("Content-Type", "application/json") |
| 45 | w.WriteHeader(http.StatusOK) |
| 46 | fmt.Fprintf(w, ` |
| 47 | { |
| 48 | "volume": { |
| 49 | "display_name": "vol-001", |
Joe Topjian | b75567d | 2015-02-06 04:23:16 +0000 | [diff] [blame] | 50 | "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", |
| 51 | "attachments": [ |
| 52 | { |
| 53 | "device": "/dev/vde", |
| 54 | "server_id": "a740d24b-dc5b-4d59-ac75-53971c2920ba", |
| 55 | "id": "d6da11e5-2ed3-413e-88d8-b772ba62193d", |
| 56 | "volume_id": "d6da11e5-2ed3-413e-88d8-b772ba62193d" |
| 57 | } |
| 58 | ] |
| 59 | } |
Jamie Hannaford | 449c4ac | 2014-10-21 09:58:02 +0200 | [diff] [blame] | 60 | } |
| 61 | `) |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | func MockCreateResponse(t *testing.T) { |
| 66 | th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) { |
| 67 | th.TestMethod(t, r, "POST") |
| 68 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 69 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 70 | th.TestHeader(t, r, "Accept", "application/json") |
| 71 | th.TestJSONRequest(t, r, ` |
| 72 | { |
| 73 | "volume": { |
Jamie Hannaford | 59f2207 | 2014-10-23 17:00:59 +0200 | [diff] [blame] | 74 | "size": 75 |
Jamie Hannaford | 449c4ac | 2014-10-21 09:58:02 +0200 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | `) |
| 78 | |
| 79 | w.Header().Add("Content-Type", "application/json") |
| 80 | w.WriteHeader(http.StatusCreated) |
| 81 | |
| 82 | fmt.Fprintf(w, ` |
| 83 | { |
| 84 | "volume": { |
| 85 | "size": 4, |
| 86 | "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22" |
| 87 | } |
| 88 | } |
| 89 | `) |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | func MockDeleteResponse(t *testing.T) { |
| 94 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 95 | th.TestMethod(t, r, "DELETE") |
| 96 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 97 | w.WriteHeader(http.StatusNoContent) |
| 98 | }) |
| 99 | } |
| 100 | |
| 101 | func MockUpdateResponse(t *testing.T) { |
| 102 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 103 | th.TestMethod(t, r, "PUT") |
| 104 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 105 | w.WriteHeader(http.StatusOK) |
| 106 | fmt.Fprintf(w, ` |
| 107 | { |
| 108 | "volume": { |
| 109 | "display_name": "vol-002", |
| 110 | "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22" |
| 111 | } |
| 112 | } |
| 113 | `) |
| 114 | }) |
| 115 | } |