fix(store): require compact cutoff time
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 18:48:41 +00:00
parent 39fddb8043
commit ecafc84e10
2 changed files with 15 additions and 0 deletions

View file

@ -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

View file

@ -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),