forked from s-mang/test2doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_test.go
40 lines (29 loc) · 905 Bytes
/
response_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package doc
import (
"bytes"
"io"
"net/http"
"net/http/httptest"
)
var testResponseBody = `{"foo": "bar"}`
func (t *suite) TestNewResponse_ResponseBodyIsCorrectlyCopied() {
body := bytes.NewBuffer([]byte(testRequestBody))
req, err := http.NewRequest("POST", "http://httpbin.org/post", body)
t.Must(t.Nil(err))
w := httptest.NewRecorder()
testResponseHandler(w, req)
apiResp := NewResponse(w)
t.Equal(string(apiResp.Body), testResponseBody)
}
func (t *suite) TestNewResponse_OriginalResponseBodyDoesNotChange() {
body := bytes.NewBuffer([]byte(testRequestBody))
req, err := http.NewRequest("POST", "http://httpbin.org/post", body)
t.Must(t.Nil(err))
w := httptest.NewRecorder()
testResponseHandler(w, req)
_ = NewResponse(w)
t.Equal(w.Body.String(), testRequestBody)
}
func testResponseHandler(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, testResponseBody)
}