13func TestLoggingHandler_ServeHTTP(t *testing.T) {
18 ExpectedLogMessage string
20 {defaultRequestLoggingFormat, fmt.Sprintf("127.0.0.1 - - [%s] test-server GET - \"/foo/bar\" HTTP/1.1 \"\" 200 4 0", ts.Format("02/Jan/2006:15:04:05 -0700"))},
21 {"{{.RequestMethod}}", "GET\n"},
24 for _, test := range tests {
25 buf := bytes.NewBuffer(nil)
26 handler := func(w http.ResponseWriter, req *http.Request) {
27 _, ok := w.(http.Hijacker)
29 t.Error("http.Hijacker is not available")
32 w.Write([]byte("test"))
35 h := LoggingHandler(buf, http.HandlerFunc(handler), true, test.Format)
37 r, _ := http.NewRequest("GET", "/foo/bar", nil)
38 r.RemoteAddr = "127.0.0.1"
39 r.Host = "test-server"
41 h.ServeHTTP(httptest.NewRecorder(), r)
43 actual := buf.String()
44 if !strings.Contains(actual, test.ExpectedLogMessage) {
45 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