(t *testing.T)
| 53 | } |
| 54 | |
| 55 | func 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 | |
| 80 | func TestRequestDecoder(t *testing.T) { |
| 81 | const ( |
nothing calls this directly
no test coverage detected