Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame] | 1 | // +build fixtures |
| 2 | |
Jamie Hannaford | 7afb7af | 2014-11-04 13:32:20 +0100 | [diff] [blame] | 3 | package monitors |
Jamie Hannaford | 8f87d39 | 2014-11-04 12:21:36 +0100 | [diff] [blame] | 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | "strconv" |
| 9 | "testing" |
| 10 | |
| 11 | th "github.com/rackspace/gophercloud/testhelper" |
| 12 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 13 | ) |
| 14 | |
| 15 | func _rootURL(lbID int) string { |
| 16 | return "/loadbalancers/" + strconv.Itoa(lbID) + "/healthmonitor" |
| 17 | } |
| 18 | |
Jamie Hannaford | 7afb7af | 2014-11-04 13:32:20 +0100 | [diff] [blame] | 19 | func mockGetResponse(t *testing.T, lbID int) { |
| 20 | th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | 8f87d39 | 2014-11-04 12:21:36 +0100 | [diff] [blame] | 21 | th.TestMethod(t, r, "GET") |
| 22 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 23 | |
| 24 | w.Header().Add("Content-Type", "application/json") |
| 25 | w.WriteHeader(http.StatusOK) |
| 26 | |
| 27 | fmt.Fprintf(w, ` |
| 28 | { |
| 29 | "healthMonitor": { |
| 30 | "type": "CONNECT", |
| 31 | "delay": 10, |
| 32 | "timeout": 10, |
| 33 | "attemptsBeforeDeactivation": 3 |
| 34 | } |
| 35 | } |
| 36 | `) |
| 37 | }) |
| 38 | } |
| 39 | |
Jamie Hannaford | 7afb7af | 2014-11-04 13:32:20 +0100 | [diff] [blame] | 40 | func mockUpdateConnectResponse(t *testing.T, lbID int) { |
| 41 | th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | 8f87d39 | 2014-11-04 12:21:36 +0100 | [diff] [blame] | 42 | th.TestMethod(t, r, "PUT") |
| 43 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 44 | |
| 45 | th.TestJSONRequest(t, r, ` |
| 46 | { |
| 47 | "healthMonitor": { |
| 48 | "type": "CONNECT", |
| 49 | "delay": 10, |
| 50 | "timeout": 10, |
| 51 | "attemptsBeforeDeactivation": 3 |
| 52 | } |
| 53 | } |
| 54 | `) |
| 55 | |
Jamie Hannaford | 2592f1f | 2014-11-06 11:10:38 +0100 | [diff] [blame] | 56 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | 8f87d39 | 2014-11-04 12:21:36 +0100 | [diff] [blame] | 57 | }) |
| 58 | } |
| 59 | |
Jamie Hannaford | 7afb7af | 2014-11-04 13:32:20 +0100 | [diff] [blame] | 60 | func mockUpdateHTTPResponse(t *testing.T, lbID int) { |
| 61 | th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) { |
| 62 | th.TestMethod(t, r, "PUT") |
| 63 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 64 | |
| 65 | th.TestJSONRequest(t, r, ` |
| 66 | { |
| 67 | "healthMonitor": { |
| 68 | "attemptsBeforeDeactivation": 3, |
| 69 | "bodyRegex": "{regex}", |
| 70 | "delay": 10, |
| 71 | "path": "/foo", |
| 72 | "statusRegex": "200", |
| 73 | "timeout": 10, |
| 74 | "type": "HTTPS" |
| 75 | } |
| 76 | } |
| 77 | `) |
| 78 | |
Jamie Hannaford | 2592f1f | 2014-11-06 11:10:38 +0100 | [diff] [blame] | 79 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | 7afb7af | 2014-11-04 13:32:20 +0100 | [diff] [blame] | 80 | }) |
| 81 | } |
| 82 | |
| 83 | func mockDeleteResponse(t *testing.T, lbID int) { |
| 84 | th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | 8f87d39 | 2014-11-04 12:21:36 +0100 | [diff] [blame] | 85 | th.TestMethod(t, r, "DELETE") |
| 86 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
Jamie Hannaford | 2592f1f | 2014-11-06 11:10:38 +0100 | [diff] [blame] | 87 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | 8f87d39 | 2014-11-04 12:21:36 +0100 | [diff] [blame] | 88 | }) |
| 89 | } |