blob: a1b8697c2a73464329567a78dec5d711a08e6b35 [file] [log] [blame]
Jamie Hannaford449c4ac2014-10-21 09:58:02 +02001package 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", 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 "id": "289da7f8-6440-407c-9fb4-7db01ec49164",
25 "display_name": "vol-001"
26 },
27 {
28 "id": "96c3bda7-c82a-4f50-be73-ca7621794835",
29 "display_name": "vol-002"
30 }
31 ]
32 }
33 `)
34 })
35}
36
37func MockGetResponse(t *testing.T) {
38 th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
39 th.TestMethod(t, r, "GET")
40 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
41
42 w.Header().Add("Content-Type", "application/json")
43 w.WriteHeader(http.StatusOK)
44 fmt.Fprintf(w, `
45{
46 "volume": {
47 "display_name": "vol-001",
Joe Topjianb75567d2015-02-06 04:23:16 +000048 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
49 "attachments": [
50 {
51 "device": "/dev/vde",
52 "server_id": "a740d24b-dc5b-4d59-ac75-53971c2920ba",
53 "id": "d6da11e5-2ed3-413e-88d8-b772ba62193d",
54 "volume_id": "d6da11e5-2ed3-413e-88d8-b772ba62193d"
55 }
56 ]
57 }
Jamie Hannaford449c4ac2014-10-21 09:58:02 +020058}
59 `)
60 })
61}
62
63func MockCreateResponse(t *testing.T) {
64 th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
65 th.TestMethod(t, r, "POST")
66 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
67 th.TestHeader(t, r, "Content-Type", "application/json")
68 th.TestHeader(t, r, "Accept", "application/json")
69 th.TestJSONRequest(t, r, `
70{
71 "volume": {
Jamie Hannaford59f22072014-10-23 17:00:59 +020072 "size": 75
Jamie Hannaford449c4ac2014-10-21 09:58:02 +020073 }
74}
75 `)
76
77 w.Header().Add("Content-Type", "application/json")
78 w.WriteHeader(http.StatusCreated)
79
80 fmt.Fprintf(w, `
81{
82 "volume": {
83 "size": 4,
84 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
85 }
86}
87 `)
88 })
89}
90
91func MockDeleteResponse(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, "DELETE")
94 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
95 w.WriteHeader(http.StatusNoContent)
96 })
97}
98
99func MockUpdateResponse(t *testing.T) {
100 th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
101 th.TestMethod(t, r, "PUT")
102 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
103 w.WriteHeader(http.StatusOK)
104 fmt.Fprintf(w, `
105 {
106 "volume": {
107 "display_name": "vol-002",
108 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
109 }
110 }
111 `)
112 })
113}