-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctx.Status() does not affect httptest.ResponseRecorder while ctx.JSON() does #4071
Comments
It seems that func TestName(t *testing.T) {
recorder := httptest.NewRecorder()
c, _ := gin.CreateTestContext(recorder)
changeResponseCode(c)
fmt.Println(c.Writer.Status()) // 204
fmt.Println(recorder.Code) // 200
} Besides, I found a related unit test in response_writer_test.go Lines 54 to 67 in c8a3adc
func TestResponseWriterWriteHeader(t *testing.T) {
testWriter := httptest.NewRecorder()
writer := &responseWriter{}
writer.reset(testWriter)
w := ResponseWriter(writer)
w.WriteHeader(http.StatusMultipleChoices)
assert.False(t, w.Written())
assert.Equal(t, http.StatusMultipleChoices, w.Status())
assert.NotEqual(t, http.StatusMultipleChoices, testWriter.Code) // ← WHY ?
w.WriteHeader(-1)
assert.Equal(t, http.StatusMultipleChoices, w.Status())
} I'm not sure why it was designed so that the original |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
ctx.Status() does not affect httptest.ResponseRecorder while ctx.JSON() does
How to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: