mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
The cleanup worker now hard-deletes package rows whose deleted_at is older than cache.deleted_retention. The default is 30 days. A value of 0 keeps the rows. The purge runs in bounded batches, with at most 100 batches per cleanup pass, and removes child rows with the package. History tables have no foreign key to packages, and stats_snapshots holds its own counts, so the purge leaves both untouched. The cleanup log line now reports purged_deleted and deleted_retention.
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDeletedRetentionDefaultsToThirtyDays(t *testing.T) {
|
|
require.Equal(t, 30*24*time.Hour, Default().Cache.DeletedRetention)
|
|
|
|
cfg, err := loadCacheYAML(t, "cache:\n default_ttl: 24h\n")
|
|
require.NoError(t, err)
|
|
require.Equal(t, 30*24*time.Hour, cfg.Cache.DeletedRetention, "an unset key keeps the default")
|
|
}
|
|
|
|
func TestDeletedRetentionParse(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
yaml string
|
|
want time.Duration
|
|
wantErr bool
|
|
}{
|
|
{name: "duration string", yaml: "cache:\n deleted_retention: 48h\n", want: 48 * time.Hour},
|
|
{name: "zero keeps rows", yaml: "cache:\n deleted_retention: 0\n", want: 0},
|
|
{name: "quoted duration", yaml: "cache:\n deleted_retention: \"720h\"\n", want: 720 * time.Hour},
|
|
{name: "negative rejected", yaml: "cache:\n deleted_retention: -1h\n", wantErr: true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
cfg, err := loadCacheYAML(t, tt.yaml)
|
|
if tt.wantErr {
|
|
require.ErrorContains(t, err, "cache.deleted_retention")
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
require.Equal(t, tt.want, cfg.Cache.DeletedRetention)
|
|
})
|
|
}
|
|
}
|