forked from mirror/gin
Change Writter to Writer. (#2079)
This commit is contained in:
parent
79840bc1c6
commit
beb879e475
|
@ -29,38 +29,38 @@ func init() {
|
|||
}
|
||||
|
||||
func TestResponseWriterReset(t *testing.T) {
|
||||
testWritter := httptest.NewRecorder()
|
||||
testWriter := httptest.NewRecorder()
|
||||
writer := &responseWriter{}
|
||||
var w ResponseWriter = writer
|
||||
|
||||
writer.reset(testWritter)
|
||||
writer.reset(testWriter)
|
||||
assert.Equal(t, -1, writer.size)
|
||||
assert.Equal(t, http.StatusOK, writer.status)
|
||||
assert.Equal(t, testWritter, writer.ResponseWriter)
|
||||
assert.Equal(t, testWriter, writer.ResponseWriter)
|
||||
assert.Equal(t, -1, w.Size())
|
||||
assert.Equal(t, http.StatusOK, w.Status())
|
||||
assert.False(t, w.Written())
|
||||
}
|
||||
|
||||
func TestResponseWriterWriteHeader(t *testing.T) {
|
||||
testWritter := httptest.NewRecorder()
|
||||
testWriter := httptest.NewRecorder()
|
||||
writer := &responseWriter{}
|
||||
writer.reset(testWritter)
|
||||
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, testWritter.Code)
|
||||
assert.NotEqual(t, http.StatusMultipleChoices, testWriter.Code)
|
||||
|
||||
w.WriteHeader(-1)
|
||||
assert.Equal(t, http.StatusMultipleChoices, w.Status())
|
||||
}
|
||||
|
||||
func TestResponseWriterWriteHeadersNow(t *testing.T) {
|
||||
testWritter := httptest.NewRecorder()
|
||||
testWriter := httptest.NewRecorder()
|
||||
writer := &responseWriter{}
|
||||
writer.reset(testWritter)
|
||||
writer.reset(testWriter)
|
||||
w := ResponseWriter(writer)
|
||||
|
||||
w.WriteHeader(http.StatusMultipleChoices)
|
||||
|
@ -68,7 +68,7 @@ func TestResponseWriterWriteHeadersNow(t *testing.T) {
|
|||
|
||||
assert.True(t, w.Written())
|
||||
assert.Equal(t, 0, w.Size())
|
||||
assert.Equal(t, http.StatusMultipleChoices, testWritter.Code)
|
||||
assert.Equal(t, http.StatusMultipleChoices, testWriter.Code)
|
||||
|
||||
writer.size = 10
|
||||
w.WriteHeaderNow()
|
||||
|
@ -76,30 +76,30 @@ func TestResponseWriterWriteHeadersNow(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResponseWriterWrite(t *testing.T) {
|
||||
testWritter := httptest.NewRecorder()
|
||||
testWriter := httptest.NewRecorder()
|
||||
writer := &responseWriter{}
|
||||
writer.reset(testWritter)
|
||||
writer.reset(testWriter)
|
||||
w := ResponseWriter(writer)
|
||||
|
||||
n, err := w.Write([]byte("hola"))
|
||||
assert.Equal(t, 4, n)
|
||||
assert.Equal(t, 4, w.Size())
|
||||
assert.Equal(t, http.StatusOK, w.Status())
|
||||
assert.Equal(t, http.StatusOK, testWritter.Code)
|
||||
assert.Equal(t, "hola", testWritter.Body.String())
|
||||
assert.Equal(t, http.StatusOK, testWriter.Code)
|
||||
assert.Equal(t, "hola", testWriter.Body.String())
|
||||
assert.NoError(t, err)
|
||||
|
||||
n, err = w.Write([]byte(" adios"))
|
||||
assert.Equal(t, 6, n)
|
||||
assert.Equal(t, 10, w.Size())
|
||||
assert.Equal(t, "hola adios", testWritter.Body.String())
|
||||
assert.Equal(t, "hola adios", testWriter.Body.String())
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestResponseWriterHijack(t *testing.T) {
|
||||
testWritter := httptest.NewRecorder()
|
||||
testWriter := httptest.NewRecorder()
|
||||
writer := &responseWriter{}
|
||||
writer.reset(testWritter)
|
||||
writer.reset(testWriter)
|
||||
w := ResponseWriter(writer)
|
||||
|
||||
assert.Panics(t, func() {
|
||||
|
|
Loading…
Reference in New Issue