diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2018-01-16 12:03:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-16 12:03:31 -0500 |
commit | 2fa7c464f019f67c5c0494aaf5ac0f5ecc1ee7a7 (patch) | |
tree | e08ff912e1924c06939f314168c3362d6f1ec0de /vendor/github.com/NYTimes/gziphandler/gzip_test.go | |
parent | f5c8a71698d0a7a16c68be220e49fe64bfee7f5c (diff) | |
download | chat-2fa7c464f019f67c5c0494aaf5ac0f5ecc1ee7a7.tar.gz chat-2fa7c464f019f67c5c0494aaf5ac0f5ecc1ee7a7.tar.bz2 chat-2fa7c464f019f67c5c0494aaf5ac0f5ecc1ee7a7.zip |
Updated dependencies and added avct/uasurfer (#8089)
* Updated dependencies and added avct/uasurfer
* Added uasurfer to NOTICE.txt
Diffstat (limited to 'vendor/github.com/NYTimes/gziphandler/gzip_test.go')
-rw-r--r-- | vendor/github.com/NYTimes/gziphandler/gzip_test.go | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/vendor/github.com/NYTimes/gziphandler/gzip_test.go b/vendor/github.com/NYTimes/gziphandler/gzip_test.go index 7decfd17b..ec1543372 100644 --- a/vendor/github.com/NYTimes/gziphandler/gzip_test.go +++ b/vendor/github.com/NYTimes/gziphandler/gzip_test.go @@ -306,23 +306,58 @@ func TestStatusCodes(t *testing.T) { } } -func TestStatusCodesFlushed(t *testing.T) { +func TestFlushBeforeWrite(t *testing.T) { + b := []byte(testBody) handler := GzipHandler(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(http.StatusNotFound) rw.(http.Flusher).Flush() - rw.Write([]byte("Not found")) + rw.Write(b) })) r := httptest.NewRequest(http.MethodGet, "/", nil) - r.Header.Set(acceptEncoding, "gzip") + r.Header.Set("Accept-Encoding", "gzip") w := httptest.NewRecorder() handler.ServeHTTP(w, r) - result := w.Result() - if result.StatusCode != http.StatusNotFound { - t.Errorf("StatusCode should have been 404 but was %d", result.StatusCode) - } + res := w.Result() + assert.Equal(t, http.StatusNotFound, res.StatusCode) + assert.Equal(t, "gzip", res.Header.Get("Content-Encoding")) + assert.NotEqual(t, b, w.Body.Bytes()) } +func TestImplementCloseNotifier(t *testing.T) { + GzipHandler(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request){ + _, ok := rw.(http.CloseNotifier) + assert.True(t, ok, "response writer must implement http.CloseNotifier") + })).ServeHTTP(&mockRWCloseNotify{}, &http.Request{}) +} + +func TestNotImplementCloseNotifier(t *testing.T) { + GzipHandler(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request){ + _, ok := rw.(http.CloseNotifier) + assert.False(t, ok, "response writer must not implement http.CloseNotifier") + })).ServeHTTP(httptest.NewRecorder(), &http.Request{}) +} + + +type mockRWCloseNotify struct{} + +func (m *mockRWCloseNotify) CloseNotify() <-chan bool { + panic("implement me") +} + +func (m *mockRWCloseNotify) Header() http.Header { + return http.Header{} +} + +func (m *mockRWCloseNotify) Write([]byte) (int, error) { + panic("implement me") +} + +func (m *mockRWCloseNotify) WriteHeader(int) { + panic("implement me") +} + + func TestIgnoreSubsequentWriteHeader(t *testing.T) { handler := GzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) |