(t *testing.T)
| 2123 | } |
| 2124 | |
| 2125 | func TestAccessLogOnFailedRequest(t *testing.T) { |
| 2126 | testLog := NewTestLog() |
| 2127 | defer testLog.Close() |
| 2128 | |
| 2129 | al := logging.NewAccessLogger(logging.Options{AccessLogOutput: testLog}) |
| 2130 | |
| 2131 | p, err := newTestProxyWithParams(`* -> "http://bad-gateway.test"`, Params{ |
| 2132 | AccessLogDisabled: false, |
| 2133 | AccessLogger: al, |
| 2134 | Flags: FlagsNone, |
| 2135 | }) |
| 2136 | if err != nil { |
| 2137 | t.Fatalf("Failed to create test proxy: %v", err) |
| 2138 | return |
| 2139 | } |
| 2140 | defer p.close() |
| 2141 | |
| 2142 | ps := httptest.NewServer(p.proxy) |
| 2143 | defer ps.Close() |
| 2144 | |
| 2145 | rsp, err := ps.Client().Get(ps.URL) |
| 2146 | if err != nil { |
| 2147 | t.Fatalf("Failed to GET: %v", err) |
| 2148 | } |
| 2149 | io.Copy(io.Discard, rsp.Body) |
| 2150 | defer rsp.Body.Close() |
| 2151 | |
| 2152 | if rsp.StatusCode != http.StatusBadGateway { |
| 2153 | t.Fatalf("failed to return 502 Bad Gateway on failing backend connection: %d", rsp.StatusCode) |
| 2154 | } |
| 2155 | |
| 2156 | const expected = `"GET / HTTP/1.1" 502 12 "-" "Go-http-client/1.1"` |
| 2157 | if err = testLog.WaitFor(expected, 100*time.Millisecond); err != nil { |
| 2158 | t.Errorf("Failed to get accesslog expected:\n%v\ngot:\n%v", expected, err) |
| 2159 | t.Logf("%s", cmp.Diff(testLog.String(), expected)) |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | func TestHopHeaderRemovalDisabled(t *testing.T) { |
| 2164 | payload := []byte("Hello World!") |
nothing calls this directly
no test coverage detected
searching dependent graphs…