blob: f3e49fa6884ede65a44e70291edaf5cc4b0d31e2 [file] [log] [blame]
Jamie Hannaford1ba046f2014-11-06 13:21:30 +01001package throttle
2
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(id int) string {
14 return "/loadbalancers/" + strconv.Itoa(id) + "/connectionthrottle"
15}
16
17func mockGetResponse(t *testing.T, lbID int) {
18 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
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 "connectionThrottle": {
28 "maxConnections": 100
29 }
30}
31`)
32 })
33}
34
35func mockCreateResponse(t *testing.T, lbID int) {
36 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
37 th.TestMethod(t, r, "PUT")
38 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
39
40 th.TestJSONRequest(t, r, `
41{
42 "connectionThrottle": {
Jamie Hannaforda307e042014-11-10 15:42:07 +010043 "maxConnectionRate": 0,
44 "maxConnections": 200,
45 "minConnections": 0,
46 "rateInterval": 0
Jamie Hannaford1ba046f2014-11-06 13:21:30 +010047 }
48}
49 `)
50
Jamie Hannaforda307e042014-11-10 15:42:07 +010051 w.WriteHeader(http.StatusAccepted)
Pratik Mallyaee675fd2015-09-14 14:07:30 -050052 fmt.Fprintf(w, `{}`)
Jamie Hannaford1ba046f2014-11-06 13:21:30 +010053 })
54}
55
56func mockDeleteResponse(t *testing.T, lbID int) {
57 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
58 th.TestMethod(t, r, "DELETE")
59 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jamie Hannaforda307e042014-11-10 15:42:07 +010060 w.WriteHeader(http.StatusAccepted)
Jamie Hannaford1ba046f2014-11-06 13:21:30 +010061 })
62}