Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame^] | 1 | // +build fixtures |
| 2 | |
Jamie Hannaford | 1ba046f | 2014-11-06 13:21:30 +0100 | [diff] [blame] | 3 | package throttle |
| 4 | |
| 5 | import ( |
| 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 | |
| 15 | func _rootURL(id int) string { |
| 16 | return "/loadbalancers/" + strconv.Itoa(id) + "/connectionthrottle" |
| 17 | } |
| 18 | |
| 19 | func 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 | |
| 37 | func 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 Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 45 | "maxConnectionRate": 0, |
| 46 | "maxConnections": 200, |
| 47 | "minConnections": 0, |
| 48 | "rateInterval": 0 |
Jamie Hannaford | 1ba046f | 2014-11-06 13:21:30 +0100 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | `) |
| 52 | |
Jamie Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 53 | w.WriteHeader(http.StatusAccepted) |
Pratik Mallya | ee675fd | 2015-09-14 14:07:30 -0500 | [diff] [blame] | 54 | fmt.Fprintf(w, `{}`) |
Jamie Hannaford | 1ba046f | 2014-11-06 13:21:30 +0100 | [diff] [blame] | 55 | }) |
| 56 | } |
| 57 | |
| 58 | func 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 Hannaford | a307e04 | 2014-11-10 15:42:07 +0100 | [diff] [blame] | 62 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | 1ba046f | 2014-11-06 13:21:30 +0100 | [diff] [blame] | 63 | }) |
| 64 | } |