blob: 077ef0470191033002232927d23c6e0c36620ef3 [file] [log] [blame]
Jamie Hannaforde5145412014-11-06 12:35:59 +01001package sessions
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) + "/sessionpersistence"
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 "sessionPersistence": {
28 "persistenceType": "HTTP_COOKIE"
29 }
30}
31`)
32 })
33}
34
35func 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 Hannaford82ce9162014-11-10 12:18:35 +010048 w.WriteHeader(http.StatusAccepted)
Pratik Mallyaee675fd2015-09-14 14:07:30 -050049 fmt.Fprintf(w, `{}`)
Jamie Hannaforde5145412014-11-06 12:35:59 +010050 })
51}
52
53func mockDisableResponse(t *testing.T, lbID int) {
54 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
55 th.TestMethod(t, r, "DELETE")
56 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jamie Hannaford82ce9162014-11-10 12:18:35 +010057 w.WriteHeader(http.StatusAccepted)
Jamie Hannaforde5145412014-11-06 12:35:59 +010058 })
59}