Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame] | 1 | // +build fixtures |
| 2 | |
Jamie Hannaford | e514541 | 2014-11-06 12:35:59 +0100 | [diff] [blame] | 3 | package sessions |
| 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) + "/sessionpersistence" |
| 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 | "sessionPersistence": { |
| 30 | "persistenceType": "HTTP_COOKIE" |
| 31 | } |
| 32 | } |
| 33 | `) |
| 34 | }) |
| 35 | } |
| 36 | |
| 37 | func mockEnableResponse(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 | "sessionPersistence": { |
| 45 | "persistenceType": "HTTP_COOKIE" |
| 46 | } |
| 47 | } |
| 48 | `) |
| 49 | |
Jamie Hannaford | 82ce916 | 2014-11-10 12:18:35 +0100 | [diff] [blame] | 50 | w.WriteHeader(http.StatusAccepted) |
Pratik Mallya | ee675fd | 2015-09-14 14:07:30 -0500 | [diff] [blame] | 51 | fmt.Fprintf(w, `{}`) |
Jamie Hannaford | e514541 | 2014-11-06 12:35:59 +0100 | [diff] [blame] | 52 | }) |
| 53 | } |
| 54 | |
| 55 | func mockDisableResponse(t *testing.T, lbID int) { |
| 56 | th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) { |
| 57 | th.TestMethod(t, r, "DELETE") |
| 58 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
Jamie Hannaford | 82ce916 | 2014-11-10 12:18:35 +0100 | [diff] [blame] | 59 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | e514541 | 2014-11-06 12:35:59 +0100 | [diff] [blame] | 60 | }) |
| 61 | } |