From b4b0aa1049fd582b30b71619e2076dc658e6f3cf Mon Sep 17 00:00:00 2001 From: Eric Phillips Date: Wed, 6 May 2026 15:33:17 -0600 Subject: [PATCH] added counter to verify upstream calls --- handler_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/handler_test.go b/handler_test.go index 9f98081..d42dbd9 100644 --- a/handler_test.go +++ b/handler_test.go @@ -7,6 +7,7 @@ import ( "net/http" "net/http/httptest" "strings" + "sync/atomic" "testing" "github.com/ewpt3ch/pkgstash/internal/cache" @@ -17,6 +18,14 @@ var ( mirror404 = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) }) ) +func mirrorOKWithCounter() (http.HandlerFunc, *atomic.Int32) { + var calls atomic.Int32 + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + calls.Add(1) + fmt.Fprint(w, "fake pkg data") + }), &calls +} + const testUrlBase = "/core/os/x86_64" func newTestServer(t *testing.T, mirrorHandler http.HandlerFunc) (*httptest.Server, *Server) { @@ -91,7 +100,8 @@ func TestHandlerPkgsMiss(t *testing.T) { func TestHandlerPkgsDBSig(t *testing.T) { - ts, _ := newTestServer(t, mirrorOK) + handler, calls := mirrorOKWithCounter() + ts, _ := newTestServer(t, handler) resp, err := http.Get(ts.URL + testUrlBase + "/core.db.sig") if err != nil { @@ -100,6 +110,9 @@ func TestHandlerPkgsDBSig(t *testing.T) { if resp.StatusCode != http.StatusNotFound { t.Errorf("expected 404 got %d", resp.StatusCode) } + if calls.Load() != 0 { + t.Error("expected no upstream calls for .db.sig") + } } func TestHandlerRefreshUnauthorized(t *testing.T) {