blob: 5d1e669920c13f884ba2d541f260ca95329816ed [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Sreekanth Pothanis07400f32015-09-08 00:26:14 -07003package testing
Jamie Hannaford449c4ac2014-10-21 09:58:02 +02004
5import (
6 "fmt"
7 "net/http"
8 "testing"
9
10 th "github.com/rackspace/gophercloud/testhelper"
11 fake "github.com/rackspace/gophercloud/testhelper/client"
12)
13
14func MockListResponse(t *testing.T) {
15 th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
16 th.TestMethod(t, r, "GET")
17 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
18
19 w.Header().Add("Content-Type", "application/json")
20 w.WriteHeader(http.StatusOK)
21
22 fmt.Fprintf(w, `
23 {
24 "volumes": [
25 {
26 "id": "289da7f8-6440-407c-9fb4-7db01ec49164",
27 "display_name": "vol-001"
28 },
29 {
30 "id": "96c3bda7-c82a-4f50-be73-ca7621794835",
31 "display_name": "vol-002"
32 }
33 ]
34 }
35 `)
36 })
37}
38
39func MockGetResponse(t *testing.T) {
40 th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
41 th.TestMethod(t, r, "GET")
42 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
43
44 w.Header().Add("Content-Type", "application/json")
45 w.WriteHeader(http.StatusOK)
46 fmt.Fprintf(w, `
47{
48 "volume": {
49 "display_name": "vol-001",
Joe Topjianb75567d2015-02-06 04:23:16 +000050 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
51 "attachments": [
52 {
53 "device": "/dev/vde",
54 "server_id": "a740d24b-dc5b-4d59-ac75-53971c2920ba",
55 "id": "d6da11e5-2ed3-413e-88d8-b772ba62193d",
56 "volume_id": "d6da11e5-2ed3-413e-88d8-b772ba62193d"
57 }
58 ]
59 }
Jamie Hannaford449c4ac2014-10-21 09:58:02 +020060}
61 `)
62 })
63}
64
65func MockCreateResponse(t *testing.T) {
66 th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
67 th.TestMethod(t, r, "POST")
68 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
69 th.TestHeader(t, r, "Content-Type", "application/json")
70 th.TestHeader(t, r, "Accept", "application/json")
71 th.TestJSONRequest(t, r, `
72{
73 "volume": {
Jamie Hannaford59f22072014-10-23 17:00:59 +020074 "size": 75
Jamie Hannaford449c4ac2014-10-21 09:58:02 +020075 }
76}
77 `)
78
79 w.Header().Add("Content-Type", "application/json")
80 w.WriteHeader(http.StatusCreated)
81
82 fmt.Fprintf(w, `
83{
84 "volume": {
85 "size": 4,
86 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
87 }
88}
89 `)
90 })
91}
92
93func MockDeleteResponse(t *testing.T) {
94 th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
95 th.TestMethod(t, r, "DELETE")
96 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
97 w.WriteHeader(http.StatusNoContent)
98 })
99}
100
101func MockUpdateResponse(t *testing.T) {
102 th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
103 th.TestMethod(t, r, "PUT")
104 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
105 w.WriteHeader(http.StatusOK)
106 fmt.Fprintf(w, `
107 {
108 "volume": {
109 "display_name": "vol-002",
110 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
111 }
112 }
113 `)
114 })
115}