12 "github.com/pusher/oauth2_proxy/logger"
15func TestLoggingHandler_ServeHTTP(t *testing.T) {
20 ExpectedLogMessage string
22 {logger.DefaultRequestLoggingFormat, fmt.Sprintf("127.0.0.1 - - [%s] test-server GET - \"/foo/bar\" HTTP/1.1 \"\" 200 4 0.000\n", logger.FormatTimestamp(ts))},
23 {"{{.RequestMethod}}", "GET\n"},
26 for _, test := range tests {
27 buf := bytes.NewBuffer(nil)
28 handler := func(w http.ResponseWriter, req *http.Request) {
29 _, ok := w.(http.Hijacker)
31 t.Error("http.Hijacker is not available")
34 w.Write([]byte("test"))
38 logger.SetReqTemplate(test.Format)
39 h := LoggingHandler(http.HandlerFunc(handler))
41 r, _ := http.NewRequest("GET", "/foo/bar", nil)
42 r.RemoteAddr = "127.0.0.1"
43 r.Host = "test-server"
45 h.ServeHTTP(httptest.NewRecorder(), r)
47 actual := buf.String()
48 if !strings.Contains(actual, test.ExpectedLogMessage) {
49 t.Errorf("Log message was\n%s\ninstead of matching \n%s", actual, test.ExpectedLogMessage)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list