From 602b3261615a76d00a2ffb2114d11ee71240bd6a Mon Sep 17 00:00:00 2001 From: Niels Widger Date: Thu, 9 Feb 2017 15:42:00 -0500 Subject: [PATCH] (Combined)LoggingHandler: Add tests for http.Push support Added two tests TestLoggingHandlerWithPush and TestCombinedLoggingHandlerWithPush in new handlers_go18_test.go file which is only built with Go 1.8 or higher. Tests ensure that the ResponseWriter passed to a handler wrapped with handlers.LoggingHandler or handlers.CombinedLoggingHandler satisfy the new http.Pusher interface. --- handlers_go18_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 handlers_go18_test.go diff --git a/handlers_go18_test.go b/handlers_go18_test.go new file mode 100644 index 0000000..c8cfa72 --- /dev/null +++ b/handlers_go18_test.go @@ -0,0 +1,34 @@ +// +build go1.8 + +package handlers + +import ( + "io/ioutil" + "net/http" + "net/http/httptest" + "testing" +) + +func TestLoggingHandlerWithPush(t *testing.T) { + handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if _, ok := w.(http.Pusher); !ok { + t.Fatalf("%T from LoggingHandler does not satisfy http.Pusher interface when built with Go >=1.8", w) + } + w.WriteHeader(200) + }) + + logger := LoggingHandler(ioutil.Discard, handler) + logger.ServeHTTP(httptest.NewRecorder(), newRequest("GET", "/")) +} + +func TestCombinedLoggingHandlerWithPush(t *testing.T) { + handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if _, ok := w.(http.Pusher); !ok { + t.Fatalf("%T from CombinedLoggingHandler does not satisfy http.Pusher interface when built with Go >=1.8", w) + } + w.WriteHeader(200) + }) + + logger := CombinedLoggingHandler(ioutil.Discard, handler) + logger.ServeHTTP(httptest.NewRecorder(), newRequest("GET", "/")) +}