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

Function TestHandleProxyHEADForwardedUncached

cmd/cache-proxy/proxy_test.go:158–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156 traceHeadersReachedOrigin.Store(r.Header.Get("traceparent") != "" || r.Header.Get("tracestate") != "")
157 w.Header().Set("Content-Type", "application/octet-stream")
158 w.WriteHeader(http.StatusOK)
159 _, _ = w.Write([]byte("hello-parquet-bytes"))
160 })
161
162 // First request: cache miss → origin fetch → cached.
163 headers := http.Header{
164 "Range": []string{"bytes=0-18"},
165 "traceparent": []string{"00-00000000000000000000000000000001-0000000000000002-01"},
166 "tracestate": []string{"vendor=value"},
167 }
168 rec := doForwardProxyRequest(proxy, "GET", originURL+"/bucket/file.parquet", headers)
169 if rec.Code != http.StatusPartialContent {
170 t.Fatalf("miss: status = %d, want 206", rec.Code)
171 }
172 if body := rec.Body.String(); body != "hello-parquet-bytes" {
173 t.Errorf("miss body = %q, want hello-parquet-bytes", body)
174 }
175 if atomic.LoadInt32(&originCalls) != 1 {
176 t.Errorf("origin calls = %d, want 1 on miss", originCalls)
177 }
178 if traceHeadersReachedOrigin.Load() {
179 t.Fatal("trace propagation headers reached cached origin fetch")
180 }
181
182 // Second request for the same URL + Range: cache hit, no extra origin call.
183 rec = doForwardProxyRequest(proxy, "GET", originURL+"/bucket/file.parquet", headers)
184 if rec.Code != http.StatusPartialContent {
185 t.Fatalf("hit: status = %d, want 206", rec.Code)
186 }
187 if atomic.LoadInt32(&originCalls) != 1 {

Callers

nothing calls this directly

Calls 4

newTestProxyFunction · 0.85
newTestServerFunction · 0.85
doForwardProxyRequestFunction · 0.85
HeaderMethod · 0.45

Tested by

no test coverage detected