jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame^] | 1 | package testing |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
| 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | fake "github.com/gophercloud/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | func MockListResponse(t *testing.T) { |
| 13 | th.Mux.HandleFunc("/volumes/detail", 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 | "volume_type": "lvmdriver-1", |
| 25 | "created_at": "2015-09-17T03:35:03.000000", |
| 26 | "bootable": "false", |
| 27 | "name": "vol-001", |
| 28 | "os-vol-mig-status-attr:name_id": null, |
| 29 | "consistencygroup_id": null, |
| 30 | "source_volid": null, |
| 31 | "os-volume-replication:driver_data": null, |
| 32 | "multiattach": false, |
| 33 | "snapshot_id": null, |
| 34 | "replication_status": "disabled", |
| 35 | "os-volume-replication:extended_status": null, |
| 36 | "encrypted": false, |
| 37 | "os-vol-host-attr:host": null, |
| 38 | "availability_zone": "nova", |
| 39 | "attachments": [ |
| 40 | { |
| 41 | "id": "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf", |
| 42 | "volume_id": "289da7f8-6440-407c-9fb4-7db01ec49164", |
| 43 | "instance_uuid": "d1c4788b-9435-42e2-9b81-29f3be1cd01f", |
| 44 | "attached_host": "stack", |
| 45 | "mountpoint": "/dev/vdc" |
| 46 | } |
| 47 | ], |
| 48 | "id": "289da7f8-6440-407c-9fb4-7db01ec49164", |
| 49 | "size": 75, |
| 50 | "user_id": "ff1ce52c03ab433aaba9108c2e3ef541", |
| 51 | "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459", |
| 52 | "os-vol-mig-status-attr:migstat": null, |
| 53 | "metadata": {"foo": "bar"}, |
| 54 | "status": "available", |
| 55 | "description": null |
| 56 | }, |
| 57 | { |
| 58 | "volume_type": "lvmdriver-1", |
| 59 | "created_at": "2015-09-17T03:32:29.000000", |
| 60 | "bootable": "false", |
| 61 | "name": "vol-002", |
| 62 | "os-vol-mig-status-attr:name_id": null, |
| 63 | "consistencygroup_id": null, |
| 64 | "source_volid": null, |
| 65 | "os-volume-replication:driver_data": null, |
| 66 | "multiattach": false, |
| 67 | "snapshot_id": null, |
| 68 | "replication_status": "disabled", |
| 69 | "os-volume-replication:extended_status": null, |
| 70 | "encrypted": false, |
| 71 | "os-vol-host-attr:host": null, |
| 72 | "availability_zone": "nova", |
| 73 | "attachments": [], |
| 74 | "id": "96c3bda7-c82a-4f50-be73-ca7621794835", |
| 75 | "size": 75, |
| 76 | "user_id": "ff1ce52c03ab433aaba9108c2e3ef541", |
| 77 | "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459", |
| 78 | "os-vol-mig-status-attr:migstat": null, |
| 79 | "metadata": {}, |
| 80 | "status": "available", |
| 81 | "description": null |
| 82 | } |
| 83 | ] |
| 84 | } |
| 85 | `) |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | func MockGetResponse(t *testing.T) { |
| 90 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 91 | th.TestMethod(t, r, "GET") |
| 92 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 93 | |
| 94 | w.Header().Add("Content-Type", "application/json") |
| 95 | w.WriteHeader(http.StatusOK) |
| 96 | fmt.Fprintf(w, ` |
| 97 | { |
| 98 | "volume": { |
| 99 | "volume_type": "lvmdriver-1", |
| 100 | "created_at": "2015-09-17T03:32:29.000000", |
| 101 | "bootable": "false", |
| 102 | "name": "vol-001", |
| 103 | "os-vol-mig-status-attr:name_id": null, |
| 104 | "consistencygroup_id": null, |
| 105 | "source_volid": null, |
| 106 | "os-volume-replication:driver_data": null, |
| 107 | "multiattach": false, |
| 108 | "snapshot_id": null, |
| 109 | "replication_status": "disabled", |
| 110 | "os-volume-replication:extended_status": null, |
| 111 | "encrypted": false, |
| 112 | "os-vol-host-attr:host": null, |
| 113 | "availability_zone": "nova", |
| 114 | "attachments": [{ |
| 115 | "attachment_id": "dbce64e3-f3b9-4423-a44f-a2b15deffa1b", |
| 116 | "id": "3eafc6f5-ed74-456d-90fb-f253f594dbae", |
| 117 | "volume_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", |
| 118 | "server_id": "d1c4788b-9435-42e2-9b81-29f3be1cd01f", |
| 119 | "host_name": "stack", |
| 120 | "device": "/dev/vdd" |
| 121 | }], |
| 122 | "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", |
| 123 | "size": 75, |
| 124 | "user_id": "ff1ce52c03ab433aaba9108c2e3ef541", |
| 125 | "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459", |
| 126 | "os-vol-mig-status-attr:migstat": null, |
| 127 | "metadata": {}, |
| 128 | "status": "available", |
| 129 | "description": null |
| 130 | } |
| 131 | } |
| 132 | `) |
| 133 | }) |
| 134 | } |
| 135 | |
| 136 | func MockCreateResponse(t *testing.T) { |
| 137 | th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) { |
| 138 | th.TestMethod(t, r, "POST") |
| 139 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 140 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 141 | th.TestHeader(t, r, "Accept", "application/json") |
| 142 | th.TestJSONRequest(t, r, ` |
| 143 | { |
| 144 | "volume": { |
| 145 | "name": "vol-001", |
| 146 | "size": 75 |
| 147 | } |
| 148 | } |
| 149 | `) |
| 150 | |
| 151 | w.Header().Add("Content-Type", "application/json") |
| 152 | w.WriteHeader(http.StatusAccepted) |
| 153 | |
| 154 | fmt.Fprintf(w, ` |
| 155 | { |
| 156 | "volume": { |
| 157 | "size": 75, |
| 158 | "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", |
| 159 | "metadata": {}, |
| 160 | "created_at": "2015-09-17T03:32:29.044216", |
| 161 | "encrypted": false, |
| 162 | "bootable": "false", |
| 163 | "availability_zone": "nova", |
| 164 | "attachments": [], |
| 165 | "user_id": "ff1ce52c03ab433aaba9108c2e3ef541", |
| 166 | "status": "creating", |
| 167 | "description": null, |
| 168 | "volume_type": "lvmdriver-1", |
| 169 | "name": "vol-001", |
| 170 | "replication_status": "disabled", |
| 171 | "consistencygroup_id": null, |
| 172 | "source_volid": null, |
| 173 | "snapshot_id": null, |
| 174 | "multiattach": false |
| 175 | } |
| 176 | } |
| 177 | `) |
| 178 | }) |
| 179 | } |
| 180 | |
| 181 | func MockDeleteResponse(t *testing.T) { |
| 182 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 183 | th.TestMethod(t, r, "DELETE") |
| 184 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 185 | w.WriteHeader(http.StatusAccepted) |
| 186 | }) |
| 187 | } |
| 188 | |
| 189 | func MockUpdateResponse(t *testing.T) { |
| 190 | th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { |
| 191 | th.TestMethod(t, r, "PUT") |
| 192 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 193 | w.WriteHeader(http.StatusOK) |
| 194 | fmt.Fprintf(w, ` |
| 195 | { |
| 196 | "volume": { |
| 197 | "name": "vol-002" |
| 198 | } |
| 199 | } |
| 200 | `) |
| 201 | }) |
| 202 | } |