(t *testing.T)
| 1988 | } |
| 1989 | |
| 1990 | func TestDisableAccessLogWithFilter(t *testing.T) { |
| 1991 | for _, ti := range []struct { |
| 1992 | msg string |
| 1993 | filter string |
| 1994 | responseCode int |
| 1995 | disabled bool |
| 1996 | }{ |
| 1997 | { |
| 1998 | msg: "disable-log-for-all", |
| 1999 | filter: "disableAccessLog()", |
| 2000 | responseCode: 201, |
| 2001 | disabled: true, |
| 2002 | }, |
| 2003 | { |
| 2004 | msg: "disable-log-match-exact", |
| 2005 | filter: "disableAccessLog(200)", |
| 2006 | responseCode: 200, |
| 2007 | disabled: true, |
| 2008 | }, |
| 2009 | { |
| 2010 | msg: "disable-log-match-prefix", |
| 2011 | filter: "disableAccessLog(3)", |
| 2012 | responseCode: 302, |
| 2013 | disabled: true, |
| 2014 | }, |
| 2015 | { |
| 2016 | msg: "disable-log-no-match", |
| 2017 | filter: "disableAccessLog(1,20,300)", |
| 2018 | responseCode: 500, |
| 2019 | disabled: false, |
| 2020 | }, |
| 2021 | } { |
| 2022 | t.Run(ti.msg, func(t *testing.T) { |
| 2023 | var buf bytes.Buffer |
| 2024 | al := logging.NewAccessLogger(logging.Options{ |
| 2025 | AccessLogOutput: &buf}) |
| 2026 | |
| 2027 | response := "7 bytes" |
| 2028 | |
| 2029 | u, _ := url.ParseRequestURI("https://www.example.org/hello") |
| 2030 | r := &http.Request{ |
| 2031 | URL: u, |
| 2032 | Method: "GET", |
| 2033 | Header: http.Header{"Connection": []string{"token"}}} |
| 2034 | w := httptest.NewRecorder() |
| 2035 | |
| 2036 | doc := fmt.Sprintf(`hello: Path("/hello") -> %s -> status(%d) -> inlineContent("%s") -> <shunt>`, ti.filter, ti.responseCode, response) |
| 2037 | |
| 2038 | tp, err := newTestProxyWithParams(doc, Params{ |
| 2039 | AccessLogDisabled: false, |
| 2040 | AccessLogger: al, |
| 2041 | }) |
| 2042 | if err != nil { |
| 2043 | t.Fatal(err) |
| 2044 | } |
| 2045 | |
| 2046 | defer tp.close() |
| 2047 |
nothing calls this directly
no test coverage detected
searching dependent graphs…