blob: c469bfbc8593a33e42402993d0fd9648ab456ee6 [file] [log] [blame]
Joe Topjian520307e2015-02-07 05:22:12 +00001// +build fixtures
2
Sreekanth Pothanis07400f32015-09-08 00:26:14 -07003package testing
Joe Topjian520307e2015-02-07 05:22:12 +00004
5import (
6 "fmt"
7 "net/http"
8 "testing"
9
10 th "github.com/rackspace/gophercloud/testhelper"
11 "github.com/rackspace/gophercloud/testhelper/client"
12)
13
14// ListOutput is a sample response to a List call.
15const ListOutput = `
16{
17 "volumeAttachments": [
18 {
19 "device": "/dev/vdd",
20 "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
21 "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
22 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803"
23 },
24 {
25 "device": "/dev/vdc",
26 "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804",
27 "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
28 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804"
29 }
30 ]
31}
32`
33
34// GetOutput is a sample response to a Get call.
35const GetOutput = `
36{
37 "volumeAttachment": {
38 "device": "/dev/vdc",
39 "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804",
40 "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
41 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804"
42 }
43}
44`
45
46// CreateOutput is a sample response to a Create call.
47const CreateOutput = `
48{
49 "volumeAttachment": {
50 "device": "/dev/vdc",
51 "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804",
52 "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
53 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804"
54 }
55}
56`
57
Joe Topjian520307e2015-02-07 05:22:12 +000058// HandleListSuccessfully configures the test server to respond to a List request.
59func HandleListSuccessfully(t *testing.T) {
60 th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/os-volume_attachments", func(w http.ResponseWriter, r *http.Request) {
61 th.TestMethod(t, r, "GET")
62 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
63
64 w.Header().Add("Content-Type", "application/json")
65 fmt.Fprintf(w, ListOutput)
66 })
67}
68
69// HandleGetSuccessfully configures the test server to respond to a Get request
70// for an existing attachment
71func HandleGetSuccessfully(t *testing.T) {
72 th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/os-volume_attachments/a26887c6-c47b-4654-abb5-dfadf7d3f804", func(w http.ResponseWriter, r *http.Request) {
73 th.TestMethod(t, r, "GET")
74 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
75
76 w.Header().Add("Content-Type", "application/json")
77 fmt.Fprintf(w, GetOutput)
78 })
79}
80
81// HandleCreateSuccessfully configures the test server to respond to a Create request
82// for a new attachment
83func HandleCreateSuccessfully(t *testing.T) {
84 th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/os-volume_attachments", func(w http.ResponseWriter, r *http.Request) {
85 th.TestMethod(t, r, "POST")
86 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
87 th.TestJSONRequest(t, r, `
88{
89 "volumeAttachment": {
90 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804",
Joe Topjian520307e2015-02-07 05:22:12 +000091 "device": "/dev/vdc"
92 }
93}
94`)
95
96 w.Header().Add("Content-Type", "application/json")
97 fmt.Fprintf(w, CreateOutput)
98 })
99}
100
101// HandleDeleteSuccessfully configures the test server to respond to a Delete request for a
102// an existing attachment
103func HandleDeleteSuccessfully(t *testing.T) {
104 th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/os-volume_attachments/a26887c6-c47b-4654-abb5-dfadf7d3f804", func(w http.ResponseWriter, r *http.Request) {
105 th.TestMethod(t, r, "DELETE")
106 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
107
108 w.WriteHeader(http.StatusAccepted)
109 })
110}