Created
December 17, 2021 16:41
-
-
Save Loupax/0a00702738982d72111d04f9e894d453 to your computer and use it in GitHub Desktop.
Generate curl request from test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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