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

Function TestServeBodyContentLength

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

Sanity check that Content-Length set via serveBody matches body length.

(t *testing.T)

Source from the content-addressed store, hash-verified

889 proxy.HandlePeerGet(rec, req)
890 if rec.Code != http.StatusOK {
891 t.Errorf("HandlePeerGet: status = %d, want 200", rec.Code)
892 }
893 if got := rec.Body.String(); got != string(body) {
894 t.Errorf("HandlePeerGet body = %q, want %q", got, body)
895 }
896}
897
898func TestHandlePeerGetDoesNotCountWorkerCacheHit(t *testing.T) {
899 proxy := newTestProxy(t)
900
901 key := strings.Repeat("e", 64)
902 body := []byte("peer-cached-payload")
903 if _, err := proxy.store.PutStream(key, bytes.NewReader(body)); err != nil {
904 t.Fatalf("seed PutStream: %v", err)
905 }
906
907 hitsBefore := counterValue(t, cacheHitsTotal)
908 req := httptest.NewRequest(http.MethodGet, "/cache/get?key="+key, nil)
909 rec := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 6

newTestProxyFunction · 0.85
newTestServerFunction · 0.85
doForwardProxyRequestFunction · 0.85
WriteMethod · 0.45
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected