github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/evacuate/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 func mockEvacuateResponse(t *testing.T, id string) { 13 th.Mux.HandleFunc("/servers/"+id+"/action", func(w http.ResponseWriter, r *http.Request) { 14 th.TestMethod(t, r, "POST") 15 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 16 th.TestJSONRequest(t, r, ` 17 { 18 "evacuate": { 19 "adminPass": "MySecretPass", 20 "host": "derp", 21 "onSharedStorage": false 22 } 23 24 } 25 `) 26 w.WriteHeader(http.StatusOK) 27 }) 28 } 29 30 func mockEvacuateResponseWithHost(t *testing.T, id string) { 31 th.Mux.HandleFunc("/servers/"+id+"/action", func(w http.ResponseWriter, r *http.Request) { 32 th.TestMethod(t, r, "POST") 33 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 34 th.TestJSONRequest(t, r, ` 35 { 36 "evacuate": { 37 "host": "derp", 38 "onSharedStorage": false 39 } 40 41 } 42 `) 43 w.WriteHeader(http.StatusOK) 44 }) 45 } 46 47 func mockEvacuateResponseWithNoOpts(t *testing.T, id string) { 48 th.Mux.HandleFunc("/servers/"+id+"/action", func(w http.ResponseWriter, r *http.Request) { 49 th.TestMethod(t, r, "POST") 50 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 51 th.TestJSONRequest(t, r, ` 52 { 53 "evacuate": { 54 "onSharedStorage": false 55 } 56 57 } 58 `) 59 w.WriteHeader(http.StatusOK) 60 }) 61 } 62 63 const EvacuateResponse = ` 64 { 65 "adminPass": "MySecretPass" 66 } 67 ` 68 69 func mockEvacuateAdminpassResponse(t *testing.T, id string) { 70 th.Mux.HandleFunc("/servers/"+id+"/action", func(w http.ResponseWriter, r *http.Request) { 71 th.TestMethod(t, r, "POST") 72 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 73 th.TestJSONRequest(t, r, ` 74 { 75 "evacuate": { 76 "onSharedStorage": false 77 } 78 } 79 `) 80 w.Header().Add("Content-Type", "application/json") 81 fmt.Fprintf(w, EvacuateResponse) 82 }) 83 }