MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestHandleConnectLogsDialFailure

Function TestHandleConnectLogsDialFailure

cmd/cache-proxy/proxy_test.go:1087–1116  ·  view source on GitHub ↗

TestHandleConnectLogsDialFailure: when the upstream is unreachable, the proxy must respond 502 to the client AND emit a Warn so the failure is visible in proxy-side logs.

(t *testing.T)

Source from the content-addressed store, hash-verified

1085 t.Fatalf("status = %d, want 501", rec.Code)
1086 }
1087 if got := rec.Body.String(); got != originBody {
1088 t.Errorf("body forwarded as %q, want verbatim origin XML", got)
1089 }
1090
1091 out := buf.String()
1092 if !strings.Contains(out, `msg="Forward-proxy origin returned non-2xx."`) {
1093 t.Errorf("expected non-2xx Warn, got:\n%s", out)
1094 }
1095 if !strings.Contains(out, `status=501`) {
1096 t.Errorf("expected status=501, got:\n%s", out)
1097 }
1098 if !strings.Contains(out, `<Code>NotImplemented</Code>`) {
1099 t.Errorf("expected origin XML <Code> prefix in body_preview, got:\n%s", out)
1100 }
1101}
1102
1103// TestHandleConnectLogsOpenAndClose drives a real HTTPS CONNECT tunnel
1104// through the proxy and asserts that:
1105//
1106// - "Forward-proxy CONNECT opened." fires when the tunnel is established;
1107// - "Forward-proxy CONNECT closed." fires once both legs finish, with the
1108// correct sent/recv byte counts.
1109//
1110// Without this, every HTTPS-routed write through the proxy (which is the
1111// path AWS S3 PUT/POST uses by default) was invisible in proxy-side logs.
1112// The client still got error codes from upstream, but operators couldn't
1113// confirm the request even reached the proxy.
1114func TestHandleConnectLogsOpenAndClose(t *testing.T) {
1115 buf, restore := captureSlog(t)
1116 defer restore()
1117
1118 // Origin: simple echo server that reflects exactly the bytes it reads.
1119 originDone := make(chan struct{})

Callers

nothing calls this directly

Calls 7

CloseMethod · 0.95
newTestProxyFunction · 0.85
captureSlogFunction · 0.70
CloseMethod · 0.65
WriteMethod · 0.45
ReadMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected