prune: fix not working option

This commit is contained in:
Michael Eischer 2025-03-22 15:19:43 +01:00
parent 3e58b15ace
commit 062cfc549d
2 changed files with 31 additions and 2 deletions

View File

@ -207,6 +207,7 @@ func runPruneWithRepo(ctx context.Context, opts PruneOptions, gopts GlobalOption
MaxUnusedBytes: opts.maxUnusedBytes,
MaxRepackBytes: opts.MaxRepackBytes,
SmallPackBytes: opts.SmallPackBytes,
RepackCacheableOnly: opts.RepackCacheableOnly,
RepackSmall: opts.RepackSmall,

View File

@ -13,14 +13,25 @@ import (
)
func testRunPrune(t testing.TB, gopts GlobalOptions, opts PruneOptions) {
t.Helper()
rtest.OK(t, testRunPruneOutput(gopts, opts))
}
func testRunPruneMustFail(t testing.TB, gopts GlobalOptions, opts PruneOptions) {
t.Helper()
err := testRunPruneOutput(gopts, opts)
rtest.Assert(t, err != nil, "expected non nil error")
}
func testRunPruneOutput(gopts GlobalOptions, opts PruneOptions) error {
oldHook := gopts.backendTestHook
gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) { return newListOnceBackend(r), nil }
defer func() {
gopts.backendTestHook = oldHook
}()
rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error {
return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error {
return runPrune(context.TODO(), opts, gopts, term)
}))
})
}
func TestPrune(t *testing.T) {
@ -237,3 +248,20 @@ func testEdgeCaseRepo(t *testing.T, tarfile string, optionsCheck CheckOptions, o
"prune should have reported an error")
}
}
func TestPruneRepackSmallerThanSmoke(t *testing.T) {
env, cleanup := withTestEnvironment(t)
defer cleanup()
// the implementation is already unit tested, so just check that
// the setting reaches its goal
createPrunableRepo(t, env)
testRunPrune(t, env.gopts, PruneOptions{
SmallPackSize: "4M",
MaxUnused: "5%",
})
testRunPruneMustFail(t, env.gopts, PruneOptions{
SmallPackSize: "500M",
MaxUnused: "5%",
})
}