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