blob: 61e601cdc29b01341c6c5021c7b06f0159deb1b9 [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannaford1ba046f2014-11-06 13:21:30 +01003package throttle
4
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(id int) string {
16 return "/loadbalancers/" + strconv.Itoa(id) + "/connectionthrottle"
17}
18
19func mockGetResponse(t *testing.T, lbID int) {
20 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
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 "connectionThrottle": {
30 "maxConnections": 100
31 }
32}
33`)
34 })
35}
36
37func mockCreateResponse(t *testing.T, lbID int) {
38 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
39 th.TestMethod(t, r, "PUT")
40 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
41
42 th.TestJSONRequest(t, r, `
43{
44 "connectionThrottle": {
Jamie Hannaforda307e042014-11-10 15:42:07 +010045 "maxConnectionRate": 0,
46 "maxConnections": 200,
47 "minConnections": 0,
48 "rateInterval": 0
Jamie Hannaford1ba046f2014-11-06 13:21:30 +010049 }
50}
51 `)
52
Jamie Hannaforda307e042014-11-10 15:42:07 +010053 w.WriteHeader(http.StatusAccepted)
Pratik Mallyaee675fd2015-09-14 14:07:30 -050054 fmt.Fprintf(w, `{}`)
Jamie Hannaford1ba046f2014-11-06 13:21:30 +010055 })
56}
57
58func mockDeleteResponse(t *testing.T, lbID int) {
59 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
60 th.TestMethod(t, r, "DELETE")
61 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jamie Hannaforda307e042014-11-10 15:42:07 +010062 w.WriteHeader(http.StatusAccepted)
Jamie Hannaford1ba046f2014-11-06 13:21:30 +010063 })
64}