Jamie Hannaford | 1ba046f | 2014-11-06 13:21:30 +0100 | [diff] [blame] | 1 | package throttle |
| 2 | |
| 3 | import ( |
| 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 | |
| 13 | func _rootURL(id int) string { |
| 14 | return "/loadbalancers/" + strconv.Itoa(id) + "/connectionthrottle" |
| 15 | } |
| 16 | |
| 17 | func 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 | |
| 35 | func 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 Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 43 | "maxConnectionRate": 0, |
| 44 | "maxConnections": 200, |
| 45 | "minConnections": 0, |
| 46 | "rateInterval": 0 |
Jamie Hannaford | 1ba046f | 2014-11-06 13:21:30 +0100 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | `) |
| 50 | |
Jamie Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 51 | w.WriteHeader(http.StatusAccepted) |
Pratik Mallya | ee675fd | 2015-09-14 14:07:30 -0500 | [diff] [blame] | 52 | fmt.Fprintf(w, `{}`) |
Jamie Hannaford | 1ba046f | 2014-11-06 13:21:30 +0100 | [diff] [blame] | 53 | }) |
| 54 | } |
| 55 | |
| 56 | func 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 Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 60 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | 1ba046f | 2014-11-06 13:21:30 +0100 | [diff] [blame] | 61 | }) |
| 62 | } |