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 MockAttachResponse(t *testing.T) { |
| 13 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 14 | func(w http.ResponseWriter, r *http.Request) { |
| 15 | th.TestMethod(t, r, "POST") |
| 16 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 17 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 18 | th.TestHeader(t, r, "Accept", "application/json") |
| 19 | th.TestJSONRequest(t, r, ` |
| 20 | { |
| 21 | "os-attach": |
| 22 | { |
| 23 | "mountpoint": "/mnt", |
| 24 | "mode": "rw", |
| 25 | "instance_uuid": "50902f4f-a974-46a0-85e9-7efc5e22dfdd" |
| 26 | } |
| 27 | } |
| 28 | `) |
| 29 | |
| 30 | w.Header().Add("Content-Type", "application/json") |
| 31 | w.WriteHeader(http.StatusAccepted) |
| 32 | |
| 33 | fmt.Fprintf(w, `{}`) |
| 34 | }) |
| 35 | } |
| 36 | |
Eugene Yakubovich | b3a4f33 | 2016-10-13 11:01:06 -0700 | [diff] [blame] | 37 | func MockBeginDetachingResponse(t *testing.T) { |
| 38 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 39 | func(w http.ResponseWriter, r *http.Request) { |
| 40 | th.TestMethod(t, r, "POST") |
| 41 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 42 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 43 | th.TestHeader(t, r, "Accept", "application/json") |
| 44 | th.TestJSONRequest(t, r, ` |
| 45 | { |
| 46 | "os-begin_detaching": {} |
| 47 | } |
| 48 | `) |
| 49 | |
| 50 | w.Header().Add("Content-Type", "application/json") |
| 51 | w.WriteHeader(http.StatusAccepted) |
| 52 | |
| 53 | fmt.Fprintf(w, `{}`) |
| 54 | }) |
| 55 | } |
| 56 | |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 57 | func MockDetachResponse(t *testing.T) { |
| 58 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 59 | func(w http.ResponseWriter, r *http.Request) { |
| 60 | th.TestMethod(t, r, "POST") |
| 61 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 62 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 63 | th.TestHeader(t, r, "Accept", "application/json") |
| 64 | th.TestJSONRequest(t, r, ` |
| 65 | { |
| 66 | "os-detach": {} |
| 67 | } |
| 68 | `) |
| 69 | |
| 70 | w.Header().Add("Content-Type", "application/json") |
| 71 | w.WriteHeader(http.StatusAccepted) |
| 72 | |
| 73 | fmt.Fprintf(w, `{}`) |
| 74 | }) |
| 75 | } |
| 76 | |
Joe Topjian | 48f36ae | 2017-02-20 14:36:44 -0700 | [diff] [blame^] | 77 | func MockUploadImageResponse(t *testing.T) { |
| 78 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 79 | func(w http.ResponseWriter, r *http.Request) { |
| 80 | th.TestMethod(t, r, "POST") |
| 81 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 82 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 83 | th.TestHeader(t, r, "Accept", "application/json") |
| 84 | th.TestJSONRequest(t, r, ` |
| 85 | { |
| 86 | "os-volume_upload_image": { |
| 87 | "container_format": "bare", |
| 88 | "force": true, |
| 89 | "image_name": "test", |
| 90 | "disk_format": "raw" |
| 91 | } |
| 92 | } |
| 93 | `) |
| 94 | |
| 95 | w.Header().Add("Content-Type", "application/json") |
| 96 | w.WriteHeader(http.StatusAccepted) |
| 97 | |
| 98 | fmt.Fprintf(w, `{}`) |
| 99 | }) |
| 100 | } |
| 101 | |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 102 | func MockReserveResponse(t *testing.T) { |
| 103 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 104 | func(w http.ResponseWriter, r *http.Request) { |
| 105 | th.TestMethod(t, r, "POST") |
| 106 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 107 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 108 | th.TestHeader(t, r, "Accept", "application/json") |
| 109 | th.TestJSONRequest(t, r, ` |
| 110 | { |
| 111 | "os-reserve": {} |
| 112 | } |
| 113 | `) |
| 114 | |
| 115 | w.Header().Add("Content-Type", "application/json") |
| 116 | w.WriteHeader(http.StatusAccepted) |
| 117 | |
| 118 | fmt.Fprintf(w, `{}`) |
| 119 | }) |
| 120 | } |
| 121 | |
| 122 | func MockUnreserveResponse(t *testing.T) { |
| 123 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 124 | func(w http.ResponseWriter, r *http.Request) { |
| 125 | th.TestMethod(t, r, "POST") |
| 126 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 127 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 128 | th.TestHeader(t, r, "Accept", "application/json") |
| 129 | th.TestJSONRequest(t, r, ` |
| 130 | { |
| 131 | "os-unreserve": {} |
| 132 | } |
| 133 | `) |
| 134 | |
| 135 | w.Header().Add("Content-Type", "application/json") |
| 136 | w.WriteHeader(http.StatusAccepted) |
| 137 | |
| 138 | fmt.Fprintf(w, `{}`) |
| 139 | }) |
| 140 | } |
| 141 | |
| 142 | func MockInitializeConnectionResponse(t *testing.T) { |
| 143 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 144 | func(w http.ResponseWriter, r *http.Request) { |
| 145 | th.TestMethod(t, r, "POST") |
| 146 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 147 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 148 | th.TestHeader(t, r, "Accept", "application/json") |
| 149 | th.TestJSONRequest(t, r, ` |
| 150 | { |
| 151 | "os-initialize_connection": |
| 152 | { |
| 153 | "connector": |
| 154 | { |
| 155 | "ip":"127.0.0.1", |
| 156 | "host":"stack", |
| 157 | "initiator":"iqn.1994-05.com.redhat:17cf566367d2", |
| 158 | "multipath": false, |
| 159 | "platform": "x86_64", |
| 160 | "os_type": "linux2" |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | `) |
| 165 | |
| 166 | w.Header().Add("Content-Type", "application/json") |
| 167 | w.WriteHeader(http.StatusAccepted) |
| 168 | |
| 169 | fmt.Fprintf(w, `{ |
| 170 | "connection_info": { |
| 171 | "data": { |
| 172 | "target_portals": [ |
| 173 | "172.31.17.48:3260" |
| 174 | ], |
| 175 | "auth_method": "CHAP", |
| 176 | "auth_username": "5MLtcsTEmNN5jFVcT6ui", |
| 177 | "access_mode": "rw", |
| 178 | "target_lun": 0, |
| 179 | "volume_id": "cd281d77-8217-4830-be95-9528227c105c", |
| 180 | "target_luns": [ |
| 181 | 0 |
| 182 | ], |
| 183 | "target_iqns": [ |
| 184 | "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c" |
| 185 | ], |
| 186 | "auth_password": "x854ZY5Re3aCkdNL", |
| 187 | "target_discovered": false, |
| 188 | "encrypted": false, |
| 189 | "qos_specs": null, |
| 190 | "target_iqn": "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c", |
| 191 | "target_portal": "172.31.17.48:3260" |
| 192 | }, |
| 193 | "driver_volume_type": "iscsi" |
| 194 | } |
| 195 | }`) |
| 196 | }) |
| 197 | } |
| 198 | |
| 199 | func MockTerminateConnectionResponse(t *testing.T) { |
| 200 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 201 | func(w http.ResponseWriter, r *http.Request) { |
| 202 | th.TestMethod(t, r, "POST") |
| 203 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 204 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 205 | th.TestHeader(t, r, "Accept", "application/json") |
| 206 | th.TestJSONRequest(t, r, ` |
| 207 | { |
| 208 | "os-terminate_connection": |
| 209 | { |
| 210 | "connector": |
| 211 | { |
| 212 | "ip":"127.0.0.1", |
| 213 | "host":"stack", |
| 214 | "initiator":"iqn.1994-05.com.redhat:17cf566367d2", |
| 215 | "multipath": true, |
| 216 | "platform": "x86_64", |
| 217 | "os_type": "linux2" |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | `) |
| 222 | |
| 223 | w.Header().Add("Content-Type", "application/json") |
| 224 | w.WriteHeader(http.StatusAccepted) |
| 225 | |
| 226 | fmt.Fprintf(w, `{}`) |
| 227 | }) |
| 228 | } |
Mario Luan | a4d4930 | 2016-09-02 11:37:24 -0400 | [diff] [blame] | 229 | |
| 230 | func MockExtendSizeResponse(t *testing.T) { |
| 231 | th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", |
| 232 | func(w http.ResponseWriter, r *http.Request) { |
| 233 | th.TestMethod(t, r, "POST") |
| 234 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 235 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 236 | th.TestHeader(t, r, "Accept", "application/json") |
| 237 | th.TestJSONRequest(t, r, ` |
| 238 | { |
| 239 | "os-extend": |
| 240 | { |
| 241 | "new_size": 3 |
| 242 | } |
| 243 | } |
| 244 | `) |
| 245 | |
| 246 | w.Header().Add("Content-Type", "application/json") |
| 247 | w.WriteHeader(http.StatusAccepted) |
| 248 | |
| 249 | fmt.Fprintf(w, `{}`) |
| 250 | }) |
| 251 | } |