MCPcopy Create free account
hub / github.com/goadesign/goa / TestRequestEncoderGetBody

Function TestRequestEncoderGetBody

http/encoding_test.go:55–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

53}
54
55func TestRequestEncoderGetBody(t *testing.T) {
56 r := &http.Request{Header: http.Header{}}
57 encoder := RequestEncoder(r)
58
59 _, err := r.Body.Read(nil)
60 assert.Error(t, err, "request Body should error (but not panic) if read before data is encoded")
61
62 _, err = r.GetBody()
63 assert.Error(t, err, "request GetBody should error (but not panic) if read before data is encoded")
64
65 err = encoder.Encode("body")
66 require.NoError(t, err)
67
68 bodyContents, err := io.ReadAll(r.Body)
69 require.NoError(t, err)
70 assert.Equal(t, `"body"`, string(bodyContents))
71
72 newBody, err := r.GetBody()
73 require.NoError(t, err)
74
75 newBodyContents, err := io.ReadAll(newBody)
76 require.NoError(t, err)
77 assert.Equal(t, bodyContents, newBodyContents)
78}
79
80func TestRequestDecoder(t *testing.T) {
81 const (

Callers

nothing calls this directly

Calls 5

GetBodyMethod · 0.80
RequestEncoderFunction · 0.70
EncodeMethod · 0.65
ReadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected