MCPcopy
hub / github.com/qustavo/httplab / TestDumpRequestWithJSON

Function TestDumpRequestWithJSON

dump_test.go:16–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestDumpRequestWithJSON(t *testing.T) {
17 t.Run("should be indented", func(t *testing.T) {
18 req, _ := http.NewRequest("GET", "/withJSON", bytes.NewBuffer(
19 []byte(`{"foo": "bar", "a": [1,2,3]}`),
20 ))
21 req.Header.Set("Content-Type", "application/json")
22
23 buf, err := DumpRequest(req)
24 require.NoError(t, err)
25 fmt.Printf("%s\n", buf)
26 })
27
28 t.Run("should be displayed as is", func(t *testing.T) {
29 req, _ := http.NewRequest("GET", "/invalidJSON", bytes.NewBuffer(
30 []byte(`invalid json`),
31 ))
32 req.Header.Set("Content-Type", "application/json")
33
34 buf, err := DumpRequest(req)
35 require.NoError(t, err)
36 fmt.Printf("%s\n", buf)
37 })
38}
39
40func TestDumpRequestHeaders(t *testing.T) {
41 t.Run("request headers should be dumped in sorted order", func(t *testing.T) {

Callers

nothing calls this directly

Calls 2

DumpRequestFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected