blob: b70e2987b455491dbbddac1caa0127bc0f36e513 [file] [log] [blame]
feiskycf0c7fe2015-11-05 22:06:17 +08001package volumes
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12func MockListResponse(t *testing.T) {
13 th.Mux.HandleFunc("/volumes/detail", func(w http.ResponseWriter, r *http.Request) {
14 th.TestMethod(t, r, "GET")
15 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
16
17 w.Header().Add("Content-Type", "application/json")
18 w.WriteHeader(http.StatusOK)
19
20 fmt.Fprintf(w, `
21 {
22 "volumes": [
23 {
24 "volume_type": "lvmdriver-1",
25 "created_at": "2015-09-17T03:35:03.000000",
26 "bootable": "false",
27 "name": "vol-001",
28 "os-vol-mig-status-attr:name_id": null,
29 "consistencygroup_id": null,
30 "source_volid": null,
31 "os-volume-replication:driver_data": null,
32 "multiattach": false,
33 "snapshot_id": null,
34 "replication_status": "disabled",
35 "os-volume-replication:extended_status": null,
36 "encrypted": false,
37 "os-vol-host-attr:host": null,
38 "availability_zone": "nova",
39 "attachments": [
40 {
41 "attachment_id": "03987cd1-0ad5-40d1-9b2a-7cc48295d4fa",
42 "id": "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf",
43 "volume_id": "289da7f8-6440-407c-9fb4-7db01ec49164",
44 "server_id": "d1c4788b-9435-42e2-9b81-29f3be1cd01f",
45 "host_name": "stack",
46 "device": "/dev/vdc"
47 }
48 ],
49 "id": "289da7f8-6440-407c-9fb4-7db01ec49164",
50 "size": 75,
51 "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
52 "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
53 "os-vol-mig-status-attr:migstat": null,
54 "metadata": {"foo": "bar"},
55 "status": "available",
56 "description": null
57 },
58 {
59 "volume_type": "lvmdriver-1",
60 "created_at": "2015-09-17T03:32:29.000000",
61 "bootable": "false",
62 "name": "vol-002",
63 "os-vol-mig-status-attr:name_id": null,
64 "consistencygroup_id": null,
65 "source_volid": null,
66 "os-volume-replication:driver_data": null,
67 "multiattach": false,
68 "snapshot_id": null,
69 "replication_status": "disabled",
70 "os-volume-replication:extended_status": null,
71 "encrypted": false,
72 "os-vol-host-attr:host": null,
73 "availability_zone": "nova",
74 "attachments": [],
75 "id": "96c3bda7-c82a-4f50-be73-ca7621794835",
76 "size": 75,
77 "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
78 "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
79 "os-vol-mig-status-attr:migstat": null,
80 "metadata": {},
81 "status": "available",
82 "description": null
83 }
84 ]
85}
86
87 `)
88 })
89}
90
91func MockGetResponse(t *testing.T) {
92 th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
93 th.TestMethod(t, r, "GET")
94 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
95
96 w.Header().Add("Content-Type", "application/json")
97 w.WriteHeader(http.StatusOK)
98 fmt.Fprintf(w, `
99{
100 "volume": {
101 "volume_type": "lvmdriver-1",
102 "created_at": "2015-09-17T03:32:29.000000",
103 "bootable": "false",
104 "name": "vol-001",
105 "os-vol-mig-status-attr:name_id": null,
106 "consistencygroup_id": null,
107 "source_volid": null,
108 "os-volume-replication:driver_data": null,
109 "multiattach": false,
110 "snapshot_id": null,
111 "replication_status": "disabled",
112 "os-volume-replication:extended_status": null,
113 "encrypted": false,
114 "os-vol-host-attr:host": null,
115 "availability_zone": "nova",
116 "attachments": [{
117 "attachment_id": "dbce64e3-f3b9-4423-a44f-a2b15deffa1b",
118 "id": "3eafc6f5-ed74-456d-90fb-f253f594dbae",
119 "volume_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
120 "server_id": "d1c4788b-9435-42e2-9b81-29f3be1cd01f",
121 "host_name": "stack",
122 "device": "/dev/vdd"
123 }],
124 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
125 "size": 75,
126 "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
127 "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
128 "os-vol-mig-status-attr:migstat": null,
129 "metadata": {},
130 "status": "available",
131 "description": null
132 }
133}
134 `)
135 })
136}
137
138func MockCreateResponse(t *testing.T) {
139 th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
140 th.TestMethod(t, r, "POST")
141 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
142 th.TestHeader(t, r, "Content-Type", "application/json")
143 th.TestHeader(t, r, "Accept", "application/json")
144 th.TestJSONRequest(t, r, `
145{
146 "volume": {
147 "name": "vol-001",
148 "size": 75
149 }
150}
151 `)
152
153 w.Header().Add("Content-Type", "application/json")
154 w.WriteHeader(http.StatusAccepted)
155
156 fmt.Fprintf(w, `
157{
158 "volume": {
159 "size": 75,
160 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
161 "metadata": {},
162 "created_at": "2015-09-17T03:32:29.044216",
163 "encrypted": false,
164 "bootable": "false",
165 "availability_zone": "nova",
166 "attachments": [],
167 "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
168 "status": "creating",
169 "description": null,
170 "volume_type": "lvmdriver-1",
171 "name": "vol-001",
172 "replication_status": "disabled",
173 "consistencygroup_id": null,
174 "source_volid": null,
175 "snapshot_id": null,
176 "multiattach": false
177 }
178}
179 `)
180 })
181}
182
183func MockDeleteResponse(t *testing.T) {
184 th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
185 th.TestMethod(t, r, "DELETE")
186 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
187 w.WriteHeader(http.StatusAccepted)
188 })
189}
190
191func MockUpdateResponse(t *testing.T) {
192 th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
193 th.TestMethod(t, r, "PUT")
194 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
195 w.WriteHeader(http.StatusOK)
196 fmt.Fprintf(w, `
197{
198 "volume": {
199 "name": "vol-002"
200 }
201}
202 `)
203 })
204}