blob: 41be2189f2ce05b8ba0fca04e891354eda69673f [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": {
43 "maxConnections": 200
44 }
45}
46 `)
47
48 w.WriteHeader(http.StatusOK)
49 })
50}
51
52func mockDeleteResponse(t *testing.T, lbID int) {
53 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
54 th.TestMethod(t, r, "DELETE")
55 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
56 w.WriteHeader(http.StatusOK)
57 })
58}