From ecafc84e107c024a2fc641ae5cbee200994383f7 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 18:48:41 +0000 Subject: [PATCH] fix(store): require compact cutoff time Co-Authored-By: Virgil --- compact.go | 7 +++++++ compact_test.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/compact.go b/compact.go index 211c5e9..280cbd4 100644 --- a/compact.go +++ b/compact.go @@ -41,6 +41,13 @@ func (compactOptions CompactOptions) Normalised() CompactOptions { // Usage example: `if err := (store.CompactOptions{Before: time.Date(2026, 3, 30, 0, 0, 0, 0, time.UTC), Format: "gzip"}).Validate(); err != nil { return }` func (compactOptions CompactOptions) Validate() error { + if compactOptions.Before.IsZero() { + return core.E( + "store.CompactOptions.Validate", + "before cutoff time is empty; use a value like time.Now().Add(-24 * time.Hour)", + nil, + ) + } switch lowerText(core.Trim(compactOptions.Format)) { case "", "gzip", "zstd": return nil diff --git a/compact_test.go b/compact_test.go index f1e2cf2..350449a 100644 --- a/compact_test.go +++ b/compact_test.go @@ -201,6 +201,14 @@ func TestCompact_CompactOptions_Good_Validate(t *testing.T) { require.NoError(t, err) } +func TestCompact_CompactOptions_Bad_ValidateMissingCutoff(t *testing.T) { + err := (CompactOptions{ + Format: "gzip", + }).Validate() + require.Error(t, err) + assert.Contains(t, err.Error(), "before cutoff time is empty") +} + func TestCompact_CompactOptions_Good_ValidateNormalisesFormatCase(t *testing.T) { err := (CompactOptions{ Before: time.Now().Add(-24 * time.Hour),