github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/volumeattach/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 th "github.com/gophercloud/gophercloud/testhelper" 9 "github.com/gophercloud/gophercloud/testhelper/client" 10 ) 11 12 // ListOutput is a sample response to a List call. 13 const ListOutput = ` 14 { 15 "volumeAttachments": [ 16 { 17 "device": "/dev/vdd", 18 "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", 19 "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0", 20 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" 21 }, 22 { 23 "device": "/dev/vdc", 24 "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", 25 "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0", 26 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804" 27 } 28 ] 29 } 30 ` 31 32 // GetOutput is a sample response to a Get call. 33 const GetOutput = ` 34 { 35 "volumeAttachment": { 36 "device": "/dev/vdc", 37 "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", 38 "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0", 39 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804" 40 } 41 } 42 ` 43 44 // CreateOutput is a sample response to a Create call. 45 const CreateOutput = ` 46 { 47 "volumeAttachment": { 48 "device": "/dev/vdc", 49 "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", 50 "serverId": "4d8c3732-a248-40ed-bebc-539a6ffd25c0", 51 "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804", 52 "tag": "foo", 53 "delete_on_termination": true 54 } 55 } 56 ` 57 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", 91 "device": "/dev/vdc", 92 "tag": "foo", 93 "delete_on_termination": true 94 } 95 } 96 `) 97 98 w.Header().Add("Content-Type", "application/json") 99 fmt.Fprintf(w, CreateOutput) 100 }) 101 } 102 103 // HandleDeleteSuccessfully configures the test server to respond to a Delete request for a 104 // an existing attachment 105 func HandleDeleteSuccessfully(t *testing.T) { 106 th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/os-volume_attachments/a26887c6-c47b-4654-abb5-dfadf7d3f804", func(w http.ResponseWriter, r *http.Request) { 107 th.TestMethod(t, r, "DELETE") 108 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 109 110 w.WriteHeader(http.StatusAccepted) 111 }) 112 }