mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
fix(cache): default metadata freshness to 24h, under the age gate
This commit is contained in:
Vendored
+2
-1
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/analytics"
|
||||
hoarderconfig "github.com/lukaszraczylo/gohoarder/pkg/config"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/errors"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/events"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
||||
@@ -172,7 +173,7 @@ func New(storage storage.StorageBackend, metadata metadata.MetadataStore, scanne
|
||||
}
|
||||
|
||||
if config.DefaultTTL == 0 {
|
||||
config.DefaultTTL = 7 * 24 * time.Hour // 7 days default
|
||||
config.DefaultTTL = hoarderconfig.DefaultMetadataTTL
|
||||
}
|
||||
|
||||
if config.CleanupInterval == 0 {
|
||||
|
||||
Vendored
+1
-1
@@ -370,7 +370,7 @@ func TestNew(t *testing.T) {
|
||||
|
||||
// Verify defaults were set
|
||||
if tt.config.DefaultTTL == 0 {
|
||||
assert.Equal(t, 7*24*time.Hour, manager.config.DefaultTTL)
|
||||
assert.Equal(t, 24*time.Hour, manager.config.DefaultTTL)
|
||||
}
|
||||
if tt.config.CleanupInterval == 0 {
|
||||
assert.Equal(t, 1*time.Hour, manager.config.CleanupInterval)
|
||||
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Clients gate on a 72h release age; a metadata page that stays fresh longer would hide the gate's inputs.
|
||||
func TestMetadataEntryDefaultTTLIsBelowReleaseAgeGate(t *testing.T) {
|
||||
h := newIdleHarness(t, Config{})
|
||||
entry := h.get(t, "left-pad", "metadata")
|
||||
|
||||
require.NotNil(t, entry.Package.ExpiresAt)
|
||||
require.Equal(t, 24*time.Hour, entry.Package.ExpiresAt.Sub(h.clock.Now()))
|
||||
}
|
||||
|
||||
func TestMetadataEntryExplicitTTLWins(t *testing.T) {
|
||||
h := newIdleHarness(t, Config{DefaultTTL: 6 * time.Hour})
|
||||
entry := h.get(t, "left-pad", "metadata")
|
||||
|
||||
require.Equal(t, 6*time.Hour, entry.Package.ExpiresAt.Sub(h.clock.Now()))
|
||||
}
|
||||
Reference in New Issue
Block a user