github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/testhelper/fixture/helper.go (about) 1 package fixture 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 SetupHandler(t *testing.T, url, method, requestBody, responseBody string, status int) { 13 th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) { 14 th.TestMethod(t, r, method) 15 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 16 17 if requestBody != "" { 18 th.TestJSONRequest(t, r, requestBody) 19 } 20 21 if responseBody != "" { 22 w.Header().Add("Content-Type", "application/json") 23 } 24 25 w.WriteHeader(status) 26 27 if responseBody != "" { 28 fmt.Fprintf(w, responseBody) 29 } 30 }) 31 }