(t *testing.T)
| 1927 | } |
| 1928 | |
| 1929 | func TestLogsAccess(t *testing.T) { |
| 1930 | var accessLog bytes.Buffer |
| 1931 | al := logging.NewAccessLogger(logging.Options{AccessLogOutput: &accessLog}) |
| 1932 | |
| 1933 | response := "7 bytes" |
| 1934 | |
| 1935 | u, _ := url.ParseRequestURI("https://www.example.org/hello") |
| 1936 | r := &http.Request{ |
| 1937 | URL: u, |
| 1938 | Method: "GET", |
| 1939 | Header: http.Header{"Connection": []string{"token"}}} |
| 1940 | w := httptest.NewRecorder() |
| 1941 | |
| 1942 | doc := fmt.Sprintf(`hello: Path("/hello") -> status(%d) -> inlineContent("%s") -> <shunt>`, http.StatusTeapot, response) |
| 1943 | |
| 1944 | tp, err := newTestProxyWithParams(doc, Params{Flags: FlagsNone, AccessLogger: al}) |
| 1945 | if err != nil { |
| 1946 | t.Fatal(err) |
| 1947 | } |
| 1948 | defer tp.close() |
| 1949 | |
| 1950 | tp.proxy.ServeHTTP(w, r) |
| 1951 | |
| 1952 | output := accessLog.String() |
| 1953 | if !strings.Contains(output, fmt.Sprintf(`"%s - -" %d %d "-" "-"`, r.Method, http.StatusTeapot, len(response))) { |
| 1954 | t.Error("failed to log access", output) |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | func TestDisableAccessLog(t *testing.T) { |
| 1959 | var buf bytes.Buffer |
nothing calls this directly
no test coverage detected
searching dependent graphs…