Jamie Hannaford | e514541 | 2014-11-06 12:35:59 +0100 | [diff] [blame] | 1 | package sessions |
| 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) + "/sessionpersistence" |
| 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 | "sessionPersistence": { |
| 28 | "persistenceType": "HTTP_COOKIE" |
| 29 | } |
| 30 | } |
| 31 | `) |
| 32 | }) |
| 33 | } |
| 34 | |
| 35 | func mockEnableResponse(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 | "sessionPersistence": { |
| 43 | "persistenceType": "HTTP_COOKIE" |
| 44 | } |
| 45 | } |
| 46 | `) |
| 47 | |
Jamie Hannaford | 82ce916 | 2014-11-10 12:18:35 +0100 | [diff] [blame] | 48 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | e514541 | 2014-11-06 12:35:59 +0100 | [diff] [blame] | 49 | }) |
| 50 | } |
| 51 | |
| 52 | func mockDisableResponse(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) |
Jamie Hannaford | 82ce916 | 2014-11-10 12:18:35 +0100 | [diff] [blame] | 56 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | e514541 | 2014-11-06 12:35:59 +0100 | [diff] [blame] | 57 | }) |
| 58 | } |