blob: e59dd6c576385b02a2412e72c84c3540a871858e [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannaforde5145412014-11-06 12:35:59 +01003package sessions
4
5import (
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
15func _rootURL(id int) string {
16 return "/loadbalancers/" + strconv.Itoa(id) + "/sessionpersistence"
17}
18
19func 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
37func 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 Hannaford82ce9162014-11-10 12:18:35 +010050 w.WriteHeader(http.StatusAccepted)
Pratik Mallyaee675fd2015-09-14 14:07:30 -050051 fmt.Fprintf(w, `{}`)
Jamie Hannaforde5145412014-11-06 12:35:59 +010052 })
53}
54
55func 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 Hannaford82ce9162014-11-10 12:18:35 +010059 w.WriteHeader(http.StatusAccepted)
Jamie Hannaforde5145412014-11-06 12:35:59 +010060 })
61}