blob: 72bfdcd0170cf66847b14696aa2d820061184682 [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannaford7afb7af2014-11-04 13:32:20 +01003package monitors
Jamie Hannaford8f87d392014-11-04 12:21:36 +01004
5import (
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
15func _rootURL(lbID int) string {
16 return "/loadbalancers/" + strconv.Itoa(lbID) + "/healthmonitor"
17}
18
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010019func mockGetResponse(t *testing.T, lbID int) {
20 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford8f87d392014-11-04 12:21:36 +010021 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 Hannaford7afb7af2014-11-04 13:32:20 +010040func mockUpdateConnectResponse(t *testing.T, lbID int) {
41 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford8f87d392014-11-04 12:21:36 +010042 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 Hannaford2592f1f2014-11-06 11:10:38 +010056 w.WriteHeader(http.StatusAccepted)
Jamie Hannaford8f87d392014-11-04 12:21:36 +010057 })
58}
59
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010060func 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 Hannaford2592f1f2014-11-06 11:10:38 +010079 w.WriteHeader(http.StatusAccepted)
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010080 })
81}
82
83func mockDeleteResponse(t *testing.T, lbID int) {
84 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford8f87d392014-11-04 12:21:36 +010085 th.TestMethod(t, r, "DELETE")
86 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jamie Hannaford2592f1f2014-11-06 11:10:38 +010087 w.WriteHeader(http.StatusAccepted)
Jamie Hannaford8f87d392014-11-04 12:21:36 +010088 })
89}