blob: 080e617f674e5bcaa5703c21a88bfa8c66361f7e [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannafordfd35b502014-11-04 10:54:05 +01003package vips
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(lbID int) string {
16 return "/loadbalancers/" + strconv.Itoa(lbID) + "/virtualips"
17}
18
19func mockListResponse(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 "virtualIps": [
30 {
31 "id": 1000,
32 "address": "206.10.10.210",
33 "type": "PUBLIC"
34 }
35 ]
36}
37 `)
38 })
39}
40
41func mockCreateResponse(t *testing.T, lbID int) {
42 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
43 th.TestMethod(t, r, "POST")
44 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
45
46 th.TestJSONRequest(t, r, `
47{
48 "type":"PUBLIC",
49 "ipVersion":"IPV6"
50}
51 `)
52
53 w.Header().Add("Content-Type", "application/json")
Jamie Hannafordf7e8e1a2014-11-04 11:48:46 +010054 w.WriteHeader(http.StatusAccepted)
Jamie Hannafordfd35b502014-11-04 10:54:05 +010055
56 fmt.Fprintf(w, `
57{
58 "address":"fd24:f480:ce44:91bc:1af2:15ff:0000:0002",
59 "id":9000134,
60 "type":"PUBLIC",
61 "ipVersion":"IPV6"
62}
63 `)
64 })
65}
66
67func mockBatchDeleteResponse(t *testing.T, lbID int, ids []int) {
68 th.Mux.HandleFunc(_rootURL(lbID), func(w http.ResponseWriter, r *http.Request) {
69 th.TestMethod(t, r, "DELETE")
70 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
71
72 r.ParseForm()
73
74 for k, v := range ids {
75 fids := r.Form["id"]
76 th.AssertEquals(t, strconv.Itoa(v), fids[k])
77 }
78
79 w.WriteHeader(http.StatusAccepted)
80 })
81}
82
83func mockDeleteResponse(t *testing.T, lbID, vipID int) {
84 url := _rootURL(lbID) + "/" + strconv.Itoa(vipID)
85 th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
86 th.TestMethod(t, r, "DELETE")
87 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jamie Hannaford2592f1f2014-11-06 11:10:38 +010088 w.WriteHeader(http.StatusAccepted)
Jamie Hannafordfd35b502014-11-04 10:54:05 +010089 })
90}