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

Function TestForwardUncachedLogsSuccess

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

TestForwardUncachedLogsSuccess locks in the invariant that a successful PUT/POST through the forward-proxy path produces a log line. Pre-PR this path was completely silent, leaving operators with no proxy-side breadcrumb to correlate against a downstream client error.

(t *testing.T)

Source from the content-addressed store, hash-verified

910 proxy.HandlePeerGet(rec, req)
911
912 if rec.Code != http.StatusOK {
913 t.Fatalf("HandlePeerGet status = %d, want 200", rec.Code)
914 }
915 if rec.Body.String() != string(body) {
916 t.Fatalf("HandlePeerGet body = %q, want %q", rec.Body.String(), body)
917 }
918 if hitsAfter := counterValue(t, cacheHitsTotal); hitsAfter != hitsBefore {
919 t.Fatalf("cacheHitsTotal changed from %v to %v for peer traffic; only worker-facing local hits should count", hitsBefore, hitsAfter)
920 }
921}
922
923func TestHandlePeerRejectsInvalidKey(t *testing.T) {
924 proxy := newTestProxy(t)
925 for _, key := range []string{"", "../../etc/passwd", "deadbeef"} {
926 req := httptest.NewRequest("GET", "/cache/has?key="+key, nil)
927 rec := httptest.NewRecorder()
928 proxy.HandlePeerHas(rec, req)
929 if rec.Code != http.StatusBadRequest {
930 t.Errorf("HandlePeerHas(%q): status = %d, want 400", key, rec.Code)
931 }
932 req = httptest.NewRequest("GET", "/cache/get?key="+key, nil)
933 rec = httptest.NewRecorder()
934 proxy.HandlePeerGet(rec, req)
935 if rec.Code != http.StatusBadRequest {
936 t.Errorf("HandlePeerGet(%q): status = %d, want 400", key, rec.Code)
937 }
938 }
939}

Callers

nothing calls this directly

Calls 6

newTestProxyFunction · 0.85
newTestServerFunction · 0.85
doForwardProxyRequestFunction · 0.85
captureSlogFunction · 0.70
WriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected