diff --git a/.travis.yml b/.travis.yml index c9be8947..609ac165 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ env: before_install: - export PATH=$PATH:$GOPATH/bin - - go get golang.org/x/tools/cmd/vet + # - go get golang.org/x/tools/cmd/vet - go get golang.org/x/tools/cmd/cover - go get github.com/modocache/gover - go get github.com/mattn/goveralls diff --git a/response_test.go b/response_test.go index 26643637..e6389f54 100644 --- a/response_test.go +++ b/response_test.go @@ -64,3 +64,27 @@ func TestResponse(t *testing.T) { // reset r.reset(httptest.NewRecorder(), New()) } + +func TestResponseWriteCommit(t *testing.T) { + e := New() + w := httptest.NewRecorder() + r := NewResponse(w, e) + + // Write body, it writes header if not committed yet + s := "echo" + r.Write([]byte(s)) + + assert.Equal(t, w.Code, 200) + assert.Equal(t, w.Body.String(), s) + + assert.Equal(t, r.Status(), 200) + assert.Equal(t, r.Size(), int64(4)) + assert.True(t, r.Committed()) + + // This is ignored with warning + r.WriteHeader(400) + + assert.Equal(t, r.Status(), 200) + assert.Equal(t, r.Size(), int64(4)) + assert.True(t, r.Committed()) +}