...

Source file src/github.com/gorilla/handlers/handlers_go18_test.go

Documentation: github.com/gorilla/handlers

     1  // +build go1.8
     2  
     3  package handlers
     4  
     5  import (
     6  	"io/ioutil"
     7  	"net/http"
     8  	"net/http/httptest"
     9  	"testing"
    10  )
    11  
    12  // *httptest.ResponseRecorder doesn't implement Pusher, so wrap it.
    13  type pushRecorder struct {
    14  	*httptest.ResponseRecorder
    15  }
    16  
    17  func (pr pushRecorder) Push(target string, opts *http.PushOptions) error {
    18  	return nil
    19  }
    20  
    21  func TestLoggingHandlerWithPush(t *testing.T) {
    22  	handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
    23  		if _, ok := w.(http.Pusher); !ok {
    24  			t.Fatalf("%T from LoggingHandler does not satisfy http.Pusher interface when built with Go >=1.8", w)
    25  		}
    26  		w.WriteHeader(200)
    27  	})
    28  
    29  	logger := LoggingHandler(ioutil.Discard, handler)
    30  	logger.ServeHTTP(pushRecorder{httptest.NewRecorder()}, newRequest("GET", "/"))
    31  }
    32  
    33  func TestCombinedLoggingHandlerWithPush(t *testing.T) {
    34  	handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
    35  		if _, ok := w.(http.Pusher); !ok {
    36  			t.Fatalf("%T from CombinedLoggingHandler does not satisfy http.Pusher interface when built with Go >=1.8", w)
    37  		}
    38  		w.WriteHeader(200)
    39  	})
    40  
    41  	logger := CombinedLoggingHandler(ioutil.Discard, handler)
    42  	logger.ServeHTTP(pushRecorder{httptest.NewRecorder()}, newRequest("GET", "/"))
    43  }
    44  

View as plain text