Skip to content

Commit

Permalink
chore: patch decoder test
Browse files Browse the repository at this point in the history
  • Loading branch information
denopink committed Oct 27, 2023
1 parent 843b6f7 commit 8ade81d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion wrphttp/decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func DecodeRequestHeaders(ctx context.Context, original *http.Request) (*Entity,

// DecodeRequest is a Decoder that provides lower-level way of decoding an *http.Request
// Can work for servers that don't use a wrp.Handler
func DecodeRequest(r *http.Request, msg any) (*http.Request, error) {
func DecodeRequest(r *http.Request, _ any) (*http.Request, error) {

if _, ok := wrpcontext.GetMessage(r.Context()); ok {
// Context already contains a message, so just return the original request
Expand Down
9 changes: 4 additions & 5 deletions wrphttp/decoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func testDecodeRequestSuccess(t *testing.T) {
)

require.NoError(
wrp.NewEncoderBytes(&body, record.bodyFormat).Encode(&expected),
wrp.NewEncoderBytes(&body, record.bodyFormat).Encode(expected),
)

request := httptest.NewRequest("POST", "/", bytes.NewBuffer(body))
Expand All @@ -246,15 +246,14 @@ func testDecodeRequestSuccess(t *testing.T) {
expected.Type = record.msgType
}

var msg wrp.Message
actual, err := DecodeRequest(request, &msg)
msg, ok := wrpcontext.Get[wrp.Message](actual.Context())
actual, err := DecodeRequest(request, nil)
msg, ok := wrpcontext.GetMessage(actual.Context())

assert.True(ok)
assert.Nil(err)
require.NotNil(actual)
require.NotNil(actual.Context())
assert.Equal(expected, &msg)
assert.Equal(expected, msg)

}
}
Expand Down

0 comments on commit 8ade81d

Please sign in to comment.