Jamie Hannaford | fd35b50 | 2014-11-04 10:54:05 +0100 | [diff] [blame] | 1 | package vips |
| 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(lbID int) string { |
| 14 | return "/loadbalancers/" + strconv.Itoa(lbID) + "/virtualips" |
| 15 | } |
| 16 | |
| 17 | func 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 | |
| 39 | func 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 Hannaford | f7e8e1a | 2014-11-04 11:48:46 +0100 | [diff] [blame] | 52 | w.WriteHeader(http.StatusAccepted) |
Jamie Hannaford | fd35b50 | 2014-11-04 10:54:05 +0100 | [diff] [blame] | 53 | |
| 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 | |
| 65 | func 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 | |
| 81 | func 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) |
| 86 | w.WriteHeader(http.StatusOK) |
| 87 | }) |
| 88 | } |