Files
pipelines/internal/server/storage_partial_test.go
T

54 lines
1.8 KiB
Go

package server
import (
"context"
"git.a-wan.net/alan/pipelines/internal/protocol"
"testing"
"time"
)
func TestStoragePartialMeasurementSurvivesBudgetExpiry(t *testing.T) {
f := newStorageFixture(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
f.m.scan = func(context.Context, storageInventoryConfig) (storageInventory, error) {
cancel()
return storageInventory{TotalBytes: 123, Partial: true, Categories: []storageCategory{{ID: "worktrees", Bytes: 123, Partial: true}}, Worktrees: []storageWorktree{{Path: f.workspace, Repository: f.workspace}}, Errors: []string{"measurement budget expired"}}, nil
}
got, err := f.m.overview(ctx)
if err != nil || got == nil || !got.Partial || got.TotalBytes != 123 {
t.Fatalf("partial %+v %v", got, err)
}
}
func TestStoragePartialPostScanCannotInventRemovedBytes(t *testing.T) {
f := newStorageFixture(t)
old := time.Now().Add(-40 * 24 * time.Hour)
id := f.run(t, "partial-postscan", "succeeded", old, old)
policy := protocol.StoragePolicy{MaxAgeDays: 7}
preview, err := f.m.preview(context.Background(), policy)
if err != nil {
t.Fatal(err)
}
if preview.CandidateCount != 1 {
t.Fatalf("preview %+v", preview)
}
scans := 0
f.m.scan = func(ctx context.Context, c storageInventoryConfig) (storageInventory, error) {
scans++
if scans == 1 {
return storageInventory{TotalBytes: 1 << 40}, nil
}
return storageInventory{Partial: true, TotalBytes: 0, Errors: []string{"partial after scan"}}, nil
}
result, err := f.m.apply(context.Background(), *preview)
if err != nil {
t.Fatal(err)
}
if result.RemovedCount != 1 || result.RemovedBytes != 4096 || result.TargetReached {
t.Fatalf("partial reclaim %+v", result)
}
if _, err := f.m.store.GetRun(context.Background(), id); err == nil {
t.Fatal("run was not removed")
}
}