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