fix(store): require compact cutoff time
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
39fddb8043
commit
ecafc84e10
2 changed files with 15 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue