Skip to content

Instantly share code, notes, and snippets.

@Loupax
Created December 17, 2021 16:41
Show Gist options
  • Save Loupax/0a00702738982d72111d04f9e894d453 to your computer and use it in GitHub Desktop.
Save Loupax/0a00702738982d72111d04f9e894d453 to your computer and use it in GitHub Desktop.
Generate curl request from test
func generateCurlTest(testName string, r *http.Request, w *httptest.ResponseRecorder) {
fmt.Println(fmt.Sprintf("### %s", testName))
var b []byte
if r.Body != nil {
b, _ = ioutil.ReadAll(r.Body)
}
r.Body = ioutil.NopCloser(bytes.NewBuffer(b))
command, _ := http2curl.GetCurlCommand(r)
fmt.Printf("```\n%s\n```\n", command)
r.Body = ioutil.NopCloser(bytes.NewBuffer(b))
s, _ := httputil.DumpResponse(w.Result(), true)
fmt.Printf("```\n%s\n```\n", s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment