12 "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
15func TestLoggingHandler_ServeHTTP(t *testing.T) {
24 {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)), "/foo/bar", []string{}},
25 {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)), "/foo/bar", []string{}},
26 {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)), "/foo/bar", []string{"/ping"}},
27 {logger.DefaultRequestLoggingFormat, "", "/foo/bar", []string{"/foo/bar"}},
28 {logger.DefaultRequestLoggingFormat, "", "/ping", []string{}},
29 {logger.DefaultRequestLoggingFormat, "", "/ping", []string{"/ping"}},
30 {logger.DefaultRequestLoggingFormat, "", "/ping", []string{"/ping"}},
31 {logger.DefaultRequestLoggingFormat, "", "/ping", []string{"/foo/bar", "/ping"}},
32 {"{{.RequestMethod}}", "GET\n", "/foo/bar", []string{}},
33 {"{{.RequestMethod}}", "GET\n", "/foo/bar", []string{"/ping"}},
34 {"{{.RequestMethod}}", "GET\n", "/ping", []string{}},
35 {"{{.RequestMethod}}", "", "/ping", []string{"/ping"}},
38 for _, test := range tests {
39 buf := bytes.NewBuffer(nil)
40 handler := func(w http.ResponseWriter, req *http.Request) {
41 _, ok := w.(http.Hijacker)
43 t.Error("http.Hijacker is not available")
46 w.Write([]byte("test"))
50 logger.SetReqTemplate(test.Format)
51 logger.SetExcludePaths(test.ExcludePaths)
52 h := LoggingHandler(http.HandlerFunc(handler))
54 r, _ := http.NewRequest("GET", test.Path, nil)
55 r.RemoteAddr = "127.0.0.1"
56 r.Host = "test-server"
58 h.ServeHTTP(httptest.NewRecorder(), r)
60 actual := buf.String()
61 if !strings.Contains(actual, test.ExpectedLogMessage) {
62 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