Skip to content

Commit

Permalink
(Combined)LoggingHandler: Add tests for http.Push support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nwidger committed Feb 9, 2017
1 parent 356173f commit 602b326
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions handlers_go18_test.go
Original file line number Diff line number Diff line change
@@ -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", "/"))
}

0 comments on commit 602b326

Please sign in to comment.