blob: eba5f824ad81f048bfef56cb9db95c7a4c385595 [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannaford96c666d2014-10-20 16:09:10 +02003package snapshots
4
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("/snapshots", 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 "snapshots": [
25 {
26 "id": "289da7f8-6440-407c-9fb4-7db01ec49164",
27 "display_name": "snapshot-001"
28 },
29 {
30 "id": "96c3bda7-c82a-4f50-be73-ca7621794835",
31 "display_name": "snapshot-002"
32 }
33 ]
34 }
35 `)
36 })
37}
38
39func MockGetResponse(t *testing.T) {
40 th.Mux.HandleFunc("/snapshots/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 "snapshot": {
49 "display_name": "snapshot-001",
50 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
51 }
52}
53 `)
54 })
55}
56
57func MockCreateResponse(t *testing.T) {
58 th.Mux.HandleFunc("/snapshots", func(w http.ResponseWriter, r *http.Request) {
59 th.TestMethod(t, r, "POST")
60 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
61 th.TestHeader(t, r, "Content-Type", "application/json")
62 th.TestHeader(t, r, "Accept", "application/json")
63 th.TestJSONRequest(t, r, `
64{
65 "snapshot": {
66 "volume_id": "1234",
67 "display_name": "snapshot-001"
68 }
69}
70 `)
71
72 w.Header().Add("Content-Type", "application/json")
73 w.WriteHeader(http.StatusCreated)
74
75 fmt.Fprintf(w, `
76{
77 "snapshot": {
78 "volume_id": "1234",
79 "display_name": "snapshot-001",
80 "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
81 }
82}
83 `)
84 })
85}
86
87func MockUpdateMetadataResponse(t *testing.T) {
88 th.Mux.HandleFunc("/snapshots/123/metadata", func(w http.ResponseWriter, r *http.Request) {
89 th.TestMethod(t, r, "PUT")
90 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
91 th.TestHeader(t, r, "Content-Type", "application/json")
92 th.TestJSONRequest(t, r, `
93 {
94 "metadata": {
95 "key": "v1"
96 }
97 }
98 `)
99
100 fmt.Fprintf(w, `
101 {
102 "metadata": {
103 "key": "v1"
104 }
105 }
106 `)
107 })
108}
109
110func MockDeleteResponse(t *testing.T) {
111 th.Mux.HandleFunc("/snapshots/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
112 th.TestMethod(t, r, "DELETE")
113 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
114 w.WriteHeader(http.StatusNoContent)
115 })
116}