Skip to content

Commit

Permalink
Response: test PreWrite only called once
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Jul 15, 2024
1 parent 2d291fe commit f68b0c6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,25 @@ func TestResponse(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.status) // Ensures PreWrite has been called
assert.Equal(t, http.StatusOK, res.StatusCode)
assert.Equal(t, "hello world", string(body))
})

t.Run("PreWrite_called_once", func(t *testing.T) {
resp, recorder := newTestReponse()
newWriter := &testChainedWriter{
ResponseRecorder: recorder,
}
resp.SetWriter(newWriter)
_, _ = resp.Write([]byte("hello world\n"))
_, _ = resp.Write([]byte("how are you today?"))

// TODO test PreWrite only called once
res := recorder.Result()
body, err := io.ReadAll(res.Body)
assert.NoError(t, res.Body.Close())
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.status)
assert.Equal(t, http.StatusOK, res.StatusCode)
assert.Equal(t, "hello world\nhow are you today?", string(body))
assert.Equal(t, "hello world\n", string(newWriter.prewritten))
})

t.Run("Hijack", func(t *testing.T) {
Expand Down

0 comments on commit f68b0c6

Please sign in to comment.