Skip to content
This repository was archived by the owner on Sep 27, 2020. It is now read-only.

Commit f5a9996

Browse files
committed
feat: WithJSONString
1 parent 3197003 commit f5a9996

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

client.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package webtest
22

33
import (
4+
"bytes"
45
"io"
56
"net/http"
67
"net/http/httptest"
@@ -206,6 +207,11 @@ func WithJSON(body io.Reader) Option {
206207
})
207208
}
208209

210+
// WithJSONString setup as json request
211+
func WithJSONString(body string) Option {
212+
return WithJSON(bytes.NewBufferString(body))
213+
}
214+
209215
// WithModifyRequest adds request modifyRequest
210216
func WithModifyRequest(modifyRequest func(*http.Request)) Option {
211217
return optionFunc(func(c *Config) {

integration_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestHandler(t *testing.T) {
7373
c := webtest.NewClientFromHandler(http.HandlerFunc(Add))
7474
var want interface{}
7575
got, err := c.Post("/",
76-
webtest.WithJSON(bytes.NewBufferString(`{"values": [1,2,3]}`)),
76+
webtest.WithJSONString(`{"values": [1,2,3]}`),
7777
webtest.WithTripperware(
7878
tripperware.ExpectCode(t, 200),
7979
tripperware.GetExpectedDataFromSnapshot(t, &want),
@@ -102,7 +102,7 @@ func TestHandler(t *testing.T) {
102102
},
103103
}.With(t, c,
104104
"POST", "/",
105-
webtest.WithJSON(bytes.NewBufferString(`{"values": [1,2,3]}`)),
105+
webtest.WithJSONString(`{"values": [1,2,3]}`),
106106
)
107107
})
108108
}

0 commit comments

Comments
 (0)