Skip to content

Commit

Permalink
feat: Optimize testing.http
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl committed Dec 24, 2024
1 parent 6b30537 commit 2f48470
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion contracts/support/http/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ type Body interface {
}

type Reader interface {
Reader() io.Reader
io.Reader
ContentType() string
}
57 changes: 31 additions & 26 deletions mocks/support/http/Reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions support/http/body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestBuildJSONBody(t *testing.T) {
assert.NoError(t, err)

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(reader.Reader())
_, err = buf.ReadFrom(reader)
assert.NoError(t, err)

var result map[string]any
Expand All @@ -62,7 +62,7 @@ func TestBuildFormBody(t *testing.T) {
assert.NoError(t, err)

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(reader.Reader())
_, err = buf.ReadFrom(reader)
assert.NoError(t, err)

formData, err := url.ParseQuery(buf.String())
Expand All @@ -87,7 +87,7 @@ func TestBuildMultipartBody(t *testing.T) {
assert.NoError(t, err)

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(reader.Reader())
_, err = buf.ReadFrom(reader)
assert.NoError(t, err)

contentType := reader.ContentType()
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestBuildFormBodyWithSpecialCharacters(t *testing.T) {
assert.NoError(t, err)

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(reader.Reader())
_, err = buf.ReadFrom(reader)
assert.NoError(t, err)

formData, err := url.ParseQuery(buf.String())
Expand Down
4 changes: 2 additions & 2 deletions support/http/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func newReader(body io.Reader, contentType string) http.Reader {
}
}

func (r *readerImpl) Reader() io.Reader {
return r.body
func (r *readerImpl) Read(p []byte) (n int, err error) {
return r.body.Read(p)
}

func (r *readerImpl) ContentType() string {
Expand Down

0 comments on commit 2f48470

Please sign in to comment.