Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 1 | // +build fixtures |
| 2 | |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame^] | 3 | package testing |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 4 | |
| 5 | import ( |
| 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. |
| 15 | const 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. |
| 35 | const 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. |
| 47 | const 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 Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 58 | // HandleListSuccessfully configures the test server to respond to a List request. |
| 59 | func 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 |
| 71 | func 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 |
| 83 | func 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 Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 91 | "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 |
| 103 | func 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 | } |