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

Function TestAccessLogOnFailedRequest

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

Source from the content-addressed store, hash-verified

2123}
2124
2125func 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
2163func TestHopHeaderRemovalDisabled(t *testing.T) {
2164 payload := []byte("Hello World!")

Callers

nothing calls this directly

Calls 11

NewAccessLoggerFunction · 0.92
newTestProxyWithParamsFunction · 0.85
ClientMethod · 0.80
NewTestLogFunction · 0.70
CloseMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.65
closeMethod · 0.45
CopyMethod · 0.45
WaitForMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…