diff --git a/internal/handlers/image_cache_control_internal_test.go b/internal/handlers/image_cache_control_internal_test.go index 97db3af..c056719 100644 --- a/internal/handlers/image_cache_control_internal_test.go +++ b/internal/handlers/image_cache_control_internal_test.go @@ -185,13 +185,13 @@ func TestHandleImageEnc_MaxAge(t *testing.T) { tests := []struct { name string - expires time.Time + ttl time.Duration wantAtLeast int wantAtMost int }{ - {"60 second TTL", time.Now().Add(time.Minute), 50, 60}, - {"two-year TTL", time.Now().Add(2 * 365 * 24 * time.Hour), 31536000, 31536000}, - {"no TTL", time.Time{}, 31536000, 31536000}, + {"60 second TTL", time.Minute, 50, 60}, + {"two-year TTL", 2 * 365 * 24 * time.Hour, 31536000, 31536000}, + {"no TTL", 0, 31536000, 31536000}, } for _, tt := range tests { @@ -200,6 +200,14 @@ func TestHandleImageEnc_MaxAge(t *testing.T) { h, srv := newSignedHostServer(t, slog.New(slog.DiscardHandler)) + // The expiry is set here, not in the table: a parallel subtest + // can wait behind other tests for more than the 10 seconds the + // 60 second case allows. + var expires time.Time + if tt.ttl != 0 { + expires = time.Now().Add(tt.ttl) + } + token, err := h.encGen.Generate(&imagerequest.Request{ Source: imagerequest.Source{ Host: signedHost, @@ -209,7 +217,7 @@ func TestHandleImageEnc_MaxAge(t *testing.T) { Size: imagerequest.Size{Width: 50, Height: 50}, Format: imagerequest.FormatJPEG, }, - }, tt.expires) + }, expires) if err != nil { t.Fatalf("Generate() error = %v", err) }