Skip to content

Commit e39e1d4

Browse files
Make it easier to use testutil with other test frameworks by accepting an interface, not a testing.T (#6)
Co-authored-by: Dzaka Ammar <[email protected]>
1 parent 2b2f1b3 commit e39e1d4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: request_helpers.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package testutil
1919
//
2020
// var body RequestBody
2121
// var response ResponseBody
22-
// t is *testing.T, from a unit test
22+
// t is TestReporter, use *testing.T from a unit test
2323
// e is *echo.Echo
2424
// response := NewRequest().Post("/path").WithJsonBody(body).GoWithHTTPHandler(t, e)
2525
// err := response.UnmarshalBodyToObject(&response)
@@ -31,9 +31,12 @@ import (
3131
"net/http"
3232
"net/http/httptest"
3333
"strings"
34-
"testing"
3534
)
3635

36+
type TestReporter interface {
37+
Errorf(format string, args ...any)
38+
}
39+
3740
func NewRequest() *RequestBuilder {
3841
return &RequestBuilder{
3942
Headers: make(map[string]string),
@@ -138,7 +141,7 @@ func (r *RequestBuilder) WithCookieNameValue(name, value string) *RequestBuilder
138141

139142
// GoWithHTTPHandler performs the request, it takes a pointer to a testing context
140143
// to print messages, and a http handler for request handling.
141-
func (r *RequestBuilder) GoWithHTTPHandler(t *testing.T, handler http.Handler) *CompletedRequest {
144+
func (r *RequestBuilder) GoWithHTTPHandler(t TestReporter, handler http.Handler) *CompletedRequest {
142145
if r.Error != nil {
143146
// Fail the test if we had an error
144147
t.Errorf("error constructing request: %s", r.Error)

0 commit comments

Comments
 (0)