MCPcopy Create free account
hub / github.com/zalando/skipper / TestEnableAccessLogWithFilter

Function TestEnableAccessLogWithFilter

proxy/proxy_test.go:2057–2123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2055}
2056
2057func TestEnableAccessLogWithFilter(t *testing.T) {
2058 for _, ti := range []struct {
2059 msg string
2060 filter string
2061 responseCode int
2062 shouldLog bool
2063 }{
2064 {
2065 msg: "enable-log-for-all",
2066 filter: "enableAccessLog()",
2067 responseCode: 201,
2068 shouldLog: true,
2069 },
2070 {
2071 msg: "enable-log-match-exact",
2072 filter: "enableAccessLog(200)",
2073 responseCode: 200,
2074 shouldLog: true,
2075 },
2076 {
2077 msg: "enable-log-match-prefix",
2078 filter: "enableAccessLog(3)",
2079 responseCode: 302,
2080 shouldLog: true,
2081 },
2082 {
2083 msg: "enable-log-no-match",
2084 filter: "enableAccessLog(1,20,300)",
2085 responseCode: 500,
2086 shouldLog: false,
2087 },
2088 } {
2089 t.Run(ti.msg, func(t *testing.T) {
2090 var buf bytes.Buffer
2091 al := logging.NewAccessLogger(logging.Options{
2092 AccessLogOutput: &buf})
2093
2094 response := "7 bytes"
2095
2096 u, _ := url.ParseRequestURI("https://www.example.org/hello")
2097 r := &http.Request{
2098 URL: u,
2099 Method: "GET",
2100 Header: http.Header{"Connection": []string{"token"}}}
2101 w := httptest.NewRecorder()
2102
2103 doc := fmt.Sprintf(`hello: Path("/hello") -> %s -> status(%d) -> inlineContent("%s") -> <shunt>`, ti.filter, ti.responseCode, response)
2104
2105 tp, err := newTestProxyWithParams(doc, Params{
2106 AccessLogDisabled: true,
2107 AccessLogger: al,
2108 })
2109 if err != nil {
2110 t.Fatal(err)
2111 }
2112
2113 defer tp.close()
2114

Callers

nothing calls this directly

Calls 6

NewAccessLoggerFunction · 0.92
newTestProxyWithParamsFunction · 0.85
StringMethod · 0.65
ErrorMethod · 0.65
closeMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…