Jamie Hannaford | fba65af | 2014-11-03 10:32:37 +0100 | [diff] [blame] | 1 | package lbs |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
Jamie Hannaford | 5f95e6a | 2014-10-31 16:13:44 +0100 | [diff] [blame] | 6 | "strconv" |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 7 | "testing" |
| 8 | |
| 9 | th "github.com/rackspace/gophercloud/testhelper" |
| 10 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 11 | ) |
| 12 | |
| 13 | func mockListLBResponse(t *testing.T) { |
| 14 | th.Mux.HandleFunc("/loadbalancers", func(w http.ResponseWriter, r *http.Request) { |
| 15 | th.TestMethod(t, r, "GET") |
| 16 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 17 | |
| 18 | w.Header().Add("Content-Type", "application/json") |
| 19 | w.WriteHeader(http.StatusOK) |
| 20 | |
| 21 | fmt.Fprintf(w, ` |
| 22 | { |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 23 | "loadBalancers":[ |
| 24 | { |
| 25 | "name":"lb-site1", |
| 26 | "id":71, |
| 27 | "protocol":"HTTP", |
| 28 | "port":80, |
| 29 | "algorithm":"RANDOM", |
| 30 | "status":"ACTIVE", |
| 31 | "nodeCount":3, |
| 32 | "virtualIps":[ |
| 33 | { |
| 34 | "id":403, |
| 35 | "address":"206.55.130.1", |
| 36 | "type":"PUBLIC", |
| 37 | "ipVersion":"IPV4" |
| 38 | } |
| 39 | ], |
| 40 | "created":{ |
| 41 | "time":"2010-11-30T03:23:42Z" |
| 42 | }, |
| 43 | "updated":{ |
| 44 | "time":"2010-11-30T03:23:44Z" |
| 45 | } |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 46 | }, |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 47 | { |
| 48 | "name":"lb-site2", |
| 49 | "id":72, |
| 50 | "created":{ |
| 51 | "time":"2011-11-30T03:23:42Z" |
| 52 | }, |
| 53 | "updated":{ |
| 54 | "time":"2011-11-30T03:23:44Z" |
| 55 | } |
| 56 | }, |
| 57 | { |
| 58 | "name":"lb-site3", |
| 59 | "id":73, |
| 60 | "created":{ |
| 61 | "time":"2012-11-30T03:23:42Z" |
| 62 | }, |
| 63 | "updated":{ |
| 64 | "time":"2012-11-30T03:23:44Z" |
| 65 | } |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 66 | } |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 67 | ] |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 68 | } |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 69 | `) |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 70 | }) |
| 71 | } |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 72 | |
| 73 | func mockCreateLBResponse(t *testing.T) { |
| 74 | th.Mux.HandleFunc("/loadbalancers", func(w http.ResponseWriter, r *http.Request) { |
| 75 | th.TestMethod(t, r, "POST") |
| 76 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 77 | |
| 78 | th.TestJSONRequest(t, r, ` |
| 79 | { |
| 80 | "loadBalancer": { |
| 81 | "name": "a-new-loadbalancer", |
| 82 | "port": 80, |
| 83 | "protocol": "HTTP", |
| 84 | "virtualIps": [ |
| 85 | { |
| 86 | "id": 2341 |
| 87 | }, |
| 88 | { |
| 89 | "id": 900001 |
| 90 | } |
| 91 | ], |
| 92 | "nodes": [ |
| 93 | { |
| 94 | "address": "10.1.1.1", |
| 95 | "port": 80, |
| 96 | "condition": "ENABLED" |
| 97 | } |
| 98 | ] |
| 99 | } |
| 100 | } |
| 101 | `) |
| 102 | |
| 103 | w.Header().Add("Content-Type", "application/json") |
Jamie Hannaford | 2592f1f | 2014-11-06 11:10:38 +0100 | [diff] [blame] | 104 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 105 | |
| 106 | fmt.Fprintf(w, ` |
| 107 | { |
| 108 | "loadBalancer": { |
| 109 | "name": "a-new-loadbalancer", |
| 110 | "id": 144, |
| 111 | "protocol": "HTTP", |
| 112 | "halfClosed": false, |
| 113 | "port": 83, |
| 114 | "algorithm": "RANDOM", |
| 115 | "status": "BUILD", |
| 116 | "timeout": 30, |
| 117 | "cluster": { |
| 118 | "name": "ztm-n01.staging1.lbaas.rackspace.net" |
| 119 | }, |
| 120 | "nodes": [ |
| 121 | { |
| 122 | "address": "10.1.1.1", |
| 123 | "id": 653, |
| 124 | "port": 80, |
| 125 | "status": "ONLINE", |
| 126 | "condition": "ENABLED", |
| 127 | "weight": 1 |
| 128 | } |
| 129 | ], |
| 130 | "virtualIps": [ |
| 131 | { |
| 132 | "address": "206.10.10.210", |
| 133 | "id": 39, |
| 134 | "type": "PUBLIC", |
| 135 | "ipVersion": "IPV4" |
| 136 | }, |
| 137 | { |
| 138 | "address": "2001:4801:79f1:0002:711b:be4c:0000:0021", |
| 139 | "id": 900001, |
| 140 | "type": "PUBLIC", |
| 141 | "ipVersion": "IPV6" |
| 142 | } |
| 143 | ], |
| 144 | "created": { |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 145 | "time": "2010-11-30T03:23:42Z" |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 146 | }, |
| 147 | "updated": { |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 148 | "time": "2010-11-30T03:23:44Z" |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 149 | }, |
| 150 | "connectionLogging": { |
| 151 | "enabled": false |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | `) |
| 156 | }) |
| 157 | } |
Jamie Hannaford | 1c26033 | 2014-10-31 15:57:22 +0100 | [diff] [blame] | 158 | |
Jamie Hannaford | 5f95e6a | 2014-10-31 16:13:44 +0100 | [diff] [blame] | 159 | func mockBatchDeleteLBResponse(t *testing.T, ids []int) { |
Jamie Hannaford | 1c26033 | 2014-10-31 15:57:22 +0100 | [diff] [blame] | 160 | th.Mux.HandleFunc("/loadbalancers", func(w http.ResponseWriter, r *http.Request) { |
| 161 | th.TestMethod(t, r, "DELETE") |
| 162 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
Jamie Hannaford | 5f95e6a | 2014-10-31 16:13:44 +0100 | [diff] [blame] | 163 | |
| 164 | r.ParseForm() |
| 165 | |
| 166 | for k, v := range ids { |
| 167 | fids := r.Form["id"] |
| 168 | th.AssertEquals(t, strconv.Itoa(v), fids[k]) |
| 169 | } |
| 170 | |
| 171 | w.WriteHeader(http.StatusAccepted) |
| 172 | }) |
| 173 | } |
| 174 | |
| 175 | func mockDeleteLBResponse(t *testing.T, id int) { |
| 176 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), func(w http.ResponseWriter, r *http.Request) { |
| 177 | th.TestMethod(t, r, "DELETE") |
| 178 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
Jamie Hannaford | 1c26033 | 2014-10-31 15:57:22 +0100 | [diff] [blame] | 179 | w.WriteHeader(http.StatusAccepted) |
| 180 | }) |
| 181 | } |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 182 | |
| 183 | func mockGetLBResponse(t *testing.T, id int) { |
| 184 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), func(w http.ResponseWriter, r *http.Request) { |
| 185 | th.TestMethod(t, r, "GET") |
| 186 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 187 | |
| 188 | w.Header().Add("Content-Type", "application/json") |
| 189 | w.WriteHeader(http.StatusOK) |
| 190 | |
| 191 | fmt.Fprintf(w, ` |
| 192 | { |
| 193 | "loadBalancer": { |
| 194 | "id": 2000, |
| 195 | "name": "sample-loadbalancer", |
| 196 | "protocol": "HTTP", |
| 197 | "port": 80, |
| 198 | "algorithm": "RANDOM", |
| 199 | "status": "ACTIVE", |
| 200 | "timeout": 30, |
| 201 | "connectionLogging": { |
| 202 | "enabled": true |
| 203 | }, |
| 204 | "virtualIps": [ |
| 205 | { |
| 206 | "id": 1000, |
| 207 | "address": "206.10.10.210", |
| 208 | "type": "PUBLIC", |
| 209 | "ipVersion": "IPV4" |
| 210 | } |
| 211 | ], |
| 212 | "nodes": [ |
| 213 | { |
| 214 | "id": 1041, |
| 215 | "address": "10.1.1.1", |
| 216 | "port": 80, |
| 217 | "condition": "ENABLED", |
| 218 | "status": "ONLINE" |
| 219 | }, |
| 220 | { |
| 221 | "id": 1411, |
| 222 | "address": "10.1.1.2", |
| 223 | "port": 80, |
| 224 | "condition": "ENABLED", |
| 225 | "status": "ONLINE" |
| 226 | } |
| 227 | ], |
| 228 | "sessionPersistence": { |
| 229 | "persistenceType": "HTTP_COOKIE" |
| 230 | }, |
| 231 | "connectionThrottle": { |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 232 | "maxConnections": 100 |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 233 | }, |
| 234 | "cluster": { |
| 235 | "name": "c1.dfw1" |
| 236 | }, |
| 237 | "created": { |
| 238 | "time": "2010-11-30T03:23:42Z" |
| 239 | }, |
| 240 | "updated": { |
| 241 | "time": "2010-11-30T03:23:44Z" |
| 242 | }, |
| 243 | "sourceAddresses": { |
| 244 | "ipv6Public": "2001:4801:79f1:1::1/64", |
| 245 | "ipv4Servicenet": "10.0.0.0", |
| 246 | "ipv4Public": "10.12.99.28" |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | `) |
| 251 | }) |
| 252 | } |
Jamie Hannaford | 76fcc83 | 2014-10-31 16:56:50 +0100 | [diff] [blame] | 253 | |
| 254 | func mockUpdateLBResponse(t *testing.T, id int) { |
| 255 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), func(w http.ResponseWriter, r *http.Request) { |
| 256 | th.TestMethod(t, r, "PUT") |
| 257 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 258 | |
| 259 | th.TestJSONRequest(t, r, ` |
| 260 | { |
| 261 | "loadBalancer": { |
| 262 | "name": "a-new-loadbalancer", |
| 263 | "protocol": "TCP", |
| 264 | "halfClosed": true, |
| 265 | "algorithm": "RANDOM", |
| 266 | "port": 8080, |
| 267 | "timeout": 100, |
| 268 | "httpsRedirect": false |
| 269 | } |
| 270 | } |
| 271 | `) |
| 272 | |
Jamie Hannaford | 2592f1f | 2014-11-06 11:10:38 +0100 | [diff] [blame] | 273 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | 76fcc83 | 2014-10-31 16:56:50 +0100 | [diff] [blame] | 274 | }) |
| 275 | } |
Jamie Hannaford | 4ab9aea | 2014-11-04 14:38:06 +0100 | [diff] [blame] | 276 | |
| 277 | func mockListProtocolsResponse(t *testing.T) { |
| 278 | th.Mux.HandleFunc("/loadbalancers/protocols", func(w http.ResponseWriter, r *http.Request) { |
| 279 | th.TestMethod(t, r, "GET") |
| 280 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 281 | |
| 282 | w.Header().Add("Content-Type", "application/json") |
| 283 | w.WriteHeader(http.StatusOK) |
| 284 | |
| 285 | fmt.Fprintf(w, ` |
| 286 | { |
| 287 | "protocols": [ |
| 288 | { |
| 289 | "name": "DNS_TCP", |
| 290 | "port": 53 |
| 291 | }, |
| 292 | { |
| 293 | "name": "DNS_UDP", |
| 294 | "port": 53 |
| 295 | }, |
| 296 | { |
| 297 | "name": "FTP", |
| 298 | "port": 21 |
| 299 | }, |
| 300 | { |
| 301 | "name": "HTTP", |
| 302 | "port": 80 |
| 303 | }, |
| 304 | { |
| 305 | "name": "HTTPS", |
| 306 | "port": 443 |
| 307 | }, |
| 308 | { |
| 309 | "name": "IMAPS", |
| 310 | "port": 993 |
| 311 | }, |
| 312 | { |
| 313 | "name": "IMAPv4", |
| 314 | "port": 143 |
| 315 | }, |
| 316 | { |
| 317 | "name": "LDAP", |
| 318 | "port": 389 |
| 319 | }, |
| 320 | { |
| 321 | "name": "LDAPS", |
| 322 | "port": 636 |
| 323 | }, |
| 324 | { |
| 325 | "name": "MYSQL", |
| 326 | "port": 3306 |
| 327 | }, |
| 328 | { |
| 329 | "name": "POP3", |
| 330 | "port": 110 |
| 331 | }, |
| 332 | { |
| 333 | "name": "POP3S", |
| 334 | "port": 995 |
| 335 | }, |
| 336 | { |
| 337 | "name": "SMTP", |
| 338 | "port": 25 |
| 339 | }, |
| 340 | { |
| 341 | "name": "TCP", |
| 342 | "port": 0 |
| 343 | }, |
| 344 | { |
| 345 | "name": "TCP_CLIENT_FIRST", |
| 346 | "port": 0 |
| 347 | }, |
| 348 | { |
| 349 | "name": "UDP", |
| 350 | "port": 0 |
| 351 | }, |
| 352 | { |
| 353 | "name": "UDP_STREAM", |
| 354 | "port": 0 |
| 355 | }, |
| 356 | { |
| 357 | "name": "SFTP", |
| 358 | "port": 22 |
| 359 | }, |
| 360 | { |
| 361 | "name": "TCP_STREAM", |
| 362 | "port": 0 |
| 363 | } |
| 364 | ] |
| 365 | } |
| 366 | `) |
| 367 | }) |
| 368 | } |
Jamie Hannaford | 4633628 | 2014-11-04 14:48:20 +0100 | [diff] [blame] | 369 | |
| 370 | func mockListAlgorithmsResponse(t *testing.T) { |
| 371 | th.Mux.HandleFunc("/loadbalancers/algorithms", func(w http.ResponseWriter, r *http.Request) { |
| 372 | th.TestMethod(t, r, "GET") |
| 373 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 374 | |
| 375 | w.Header().Add("Content-Type", "application/json") |
| 376 | w.WriteHeader(http.StatusOK) |
| 377 | |
| 378 | fmt.Fprintf(w, ` |
| 379 | { |
| 380 | "algorithms": [ |
| 381 | { |
| 382 | "name": "LEAST_CONNECTIONS" |
| 383 | }, |
| 384 | { |
| 385 | "name": "RANDOM" |
| 386 | }, |
| 387 | { |
| 388 | "name": "ROUND_ROBIN" |
| 389 | }, |
| 390 | { |
| 391 | "name": "WEIGHTED_LEAST_CONNECTIONS" |
| 392 | }, |
| 393 | { |
| 394 | "name": "WEIGHTED_ROUND_ROBIN" |
| 395 | } |
| 396 | ] |
| 397 | } |
| 398 | `) |
| 399 | }) |
| 400 | } |
Jamie Hannaford | d78bb35 | 2014-11-07 16:36:09 +0100 | [diff] [blame] | 401 | |
| 402 | func mockGetLoggingResponse(t *testing.T, id int) { |
| 403 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/connectionlogging", func(w http.ResponseWriter, r *http.Request) { |
| 404 | th.TestMethod(t, r, "GET") |
| 405 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 406 | |
| 407 | w.Header().Add("Content-Type", "application/json") |
| 408 | w.WriteHeader(http.StatusOK) |
| 409 | |
| 410 | fmt.Fprintf(w, ` |
| 411 | { |
| 412 | "connectionLogging": { |
| 413 | "enabled": true |
| 414 | } |
| 415 | } |
| 416 | `) |
| 417 | }) |
| 418 | } |
| 419 | |
| 420 | func mockEnableLoggingResponse(t *testing.T, id int) { |
| 421 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/connectionlogging", func(w http.ResponseWriter, r *http.Request) { |
| 422 | th.TestMethod(t, r, "PUT") |
| 423 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 424 | |
| 425 | th.TestJSONRequest(t, r, ` |
| 426 | { |
| 427 | "connectionLogging":{ |
| 428 | "enabled":true |
| 429 | } |
| 430 | } |
| 431 | `) |
| 432 | |
Jamie Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 433 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | d78bb35 | 2014-11-07 16:36:09 +0100 | [diff] [blame] | 434 | }) |
| 435 | } |
| 436 | |
| 437 | func mockDisableLoggingResponse(t *testing.T, id int) { |
| 438 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/connectionlogging", func(w http.ResponseWriter, r *http.Request) { |
| 439 | th.TestMethod(t, r, "PUT") |
| 440 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 441 | |
| 442 | th.TestJSONRequest(t, r, ` |
| 443 | { |
| 444 | "connectionLogging":{ |
| 445 | "enabled":false |
| 446 | } |
| 447 | } |
| 448 | `) |
| 449 | |
Jamie Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 450 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | d78bb35 | 2014-11-07 16:36:09 +0100 | [diff] [blame] | 451 | }) |
| 452 | } |
Jamie Hannaford | da45b42 | 2014-11-10 11:00:38 +0100 | [diff] [blame] | 453 | |
| 454 | func mockGetErrorPageResponse(t *testing.T, id int) { |
| 455 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/errorpage", func(w http.ResponseWriter, r *http.Request) { |
| 456 | th.TestMethod(t, r, "GET") |
| 457 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 458 | |
| 459 | w.Header().Add("Content-Type", "application/json") |
| 460 | w.WriteHeader(http.StatusOK) |
| 461 | |
| 462 | fmt.Fprintf(w, ` |
| 463 | { |
| 464 | "errorpage": { |
| 465 | "content": "<html>DEFAULT ERROR PAGE</html>" |
| 466 | } |
| 467 | } |
| 468 | `) |
| 469 | }) |
| 470 | } |
| 471 | |
| 472 | func mockSetErrorPageResponse(t *testing.T, id int) { |
| 473 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/errorpage", func(w http.ResponseWriter, r *http.Request) { |
| 474 | th.TestMethod(t, r, "PUT") |
| 475 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 476 | |
| 477 | th.TestJSONRequest(t, r, ` |
| 478 | { |
| 479 | "errorpage": { |
| 480 | "content": "<html>New error page</html>" |
| 481 | } |
| 482 | } |
| 483 | `) |
| 484 | |
| 485 | w.WriteHeader(http.StatusOK) |
| 486 | |
| 487 | fmt.Fprintf(w, ` |
| 488 | { |
| 489 | "errorpage": { |
| 490 | "content": "<html>New error page</html>" |
| 491 | } |
| 492 | } |
| 493 | `) |
| 494 | }) |
| 495 | } |
| 496 | |
| 497 | func mockDeleteErrorPageResponse(t *testing.T, id int) { |
| 498 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/errorpage", func(w http.ResponseWriter, r *http.Request) { |
| 499 | th.TestMethod(t, r, "DELETE") |
| 500 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 501 | w.WriteHeader(http.StatusOK) |
| 502 | }) |
| 503 | } |
Jamie Hannaford | 3da6528 | 2014-11-10 11:36:16 +0100 | [diff] [blame] | 504 | |
| 505 | func mockGetStatsResponse(t *testing.T, id int) { |
| 506 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/stats", func(w http.ResponseWriter, r *http.Request) { |
| 507 | th.TestMethod(t, r, "GET") |
| 508 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 509 | |
| 510 | w.Header().Add("Content-Type", "application/json") |
| 511 | w.WriteHeader(http.StatusOK) |
| 512 | |
| 513 | fmt.Fprintf(w, ` |
| 514 | { |
| 515 | "connectTimeOut": 10, |
| 516 | "connectError": 20, |
| 517 | "connectFailure": 30, |
| 518 | "dataTimedOut": 40, |
| 519 | "keepAliveTimedOut": 50, |
| 520 | "maxConn": 60, |
| 521 | "currentConn": 40, |
| 522 | "connectTimeOutSsl": 10, |
| 523 | "connectErrorSsl": 20, |
| 524 | "connectFailureSsl": 30, |
| 525 | "dataTimedOutSsl": 40, |
| 526 | "keepAliveTimedOutSsl": 50, |
| 527 | "maxConnSsl": 60, |
| 528 | "currentConnSsl": 40 |
| 529 | } |
| 530 | `) |
| 531 | }) |
| 532 | } |
Jamie Hannaford | 20b7588 | 2014-11-10 13:39:51 +0100 | [diff] [blame] | 533 | |
| 534 | func mockGetCachingResponse(t *testing.T, id int) { |
| 535 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/contentcaching", func(w http.ResponseWriter, r *http.Request) { |
| 536 | th.TestMethod(t, r, "GET") |
| 537 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 538 | |
| 539 | w.Header().Add("Content-Type", "application/json") |
| 540 | w.WriteHeader(http.StatusOK) |
| 541 | |
| 542 | fmt.Fprintf(w, ` |
| 543 | { |
| 544 | "contentCaching": { |
| 545 | "enabled": true |
| 546 | } |
| 547 | } |
| 548 | `) |
| 549 | }) |
| 550 | } |
| 551 | |
| 552 | func mockEnableCachingResponse(t *testing.T, id int) { |
| 553 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/contentcaching", func(w http.ResponseWriter, r *http.Request) { |
| 554 | th.TestMethod(t, r, "PUT") |
| 555 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 556 | |
| 557 | th.TestJSONRequest(t, r, ` |
| 558 | { |
| 559 | "contentCaching":{ |
| 560 | "enabled":true |
| 561 | } |
| 562 | } |
| 563 | `) |
| 564 | |
Jamie Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 565 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | 20b7588 | 2014-11-10 13:39:51 +0100 | [diff] [blame] | 566 | }) |
| 567 | } |
| 568 | |
| 569 | func mockDisableCachingResponse(t *testing.T, id int) { |
| 570 | th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/contentcaching", func(w http.ResponseWriter, r *http.Request) { |
| 571 | th.TestMethod(t, r, "PUT") |
| 572 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 573 | |
| 574 | th.TestJSONRequest(t, r, ` |
| 575 | { |
| 576 | "contentCaching":{ |
| 577 | "enabled":false |
| 578 | } |
| 579 | } |
| 580 | `) |
| 581 | |
Jamie Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 582 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | 20b7588 | 2014-11-10 13:39:51 +0100 | [diff] [blame] | 583 | }) |
| 584 | } |