blob: a565abced54cda6bd2086c0eecdeb777168743cd [file] [log] [blame]
Jamie Hannaford7afb7af2014-11-04 13:32:20 +01001package monitors
Jamie Hannaford8f87d392014-11-04 12:21:36 +01002
3import (
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
13func _rootURL(lbID int) string {
14 return "/loadbalancers/" + strconv.Itoa(lbID) + "/healthmonitor"
15}
16
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010017func mockGetResponse(t *testing.T, lbID int) {
18 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford8f87d392014-11-04 12:21:36 +010019 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 Hannaford7afb7af2014-11-04 13:32:20 +010038func mockUpdateConnectResponse(t *testing.T, lbID int) {
39 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford8f87d392014-11-04 12:21:36 +010040 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 Hannaford2592f1f2014-11-06 11:10:38 +010054 w.WriteHeader(http.StatusAccepted)
Jamie Hannaford8f87d392014-11-04 12:21:36 +010055 })
56}
57
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010058func 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 Hannaford2592f1f2014-11-06 11:10:38 +010077 w.WriteHeader(http.StatusAccepted)
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010078 })
79}
80
81func mockDeleteResponse(t *testing.T, lbID int) {
82 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford8f87d392014-11-04 12:21:36 +010083 th.TestMethod(t, r, "DELETE")
84 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jamie Hannaford2592f1f2014-11-06 11:10:38 +010085 w.WriteHeader(http.StatusAccepted)
Jamie Hannaford8f87d392014-11-04 12:21:36 +010086 })
87}