refactor: static sentinel errors for #55's config validation paths (err113)

This commit is contained in:
2026-08-09 13:35:52 +00:00
parent 888c3a409a
commit 9218d7e7f6
3 changed files with 24 additions and 12 deletions

View File

@@ -9,6 +9,12 @@ import (
"testing"
)
// Static errors returned by the stub free-space probes below.
var (
errTestStatfsFailed = errors.New("statfs failed")
errTestProbeNotExpected = errors.New("probe must not be called")
)
// discardLogger returns a logger that swallows all output, for tests
// that exercise code paths which log.
func discardLogger() *slog.Logger {
@@ -205,7 +211,7 @@ func TestComputeDefaultCacheMaxBytesAppliesFloorToComputedDefault(t *testing.T)
func TestComputeDefaultCacheMaxBytesPropagatesProbeError(t *testing.T) {
t.Parallel()
probe := func(string) (uint64, error) { return 0, errors.New("statfs failed") }
probe := func(string) (uint64, error) { return 0, errTestStatfsFailed }
_, err := ComputeDefaultCacheMaxBytes(t.TempDir(), probe)
if err == nil {
@@ -284,7 +290,7 @@ func TestResolveCacheMaxBytesDoesNotOverrideExplicitValue(t *testing.T) {
probe := func(string) (uint64, error) {
t.Error("free-space probe must not be consulted for explicit values")
return 0, errors.New("probe must not be called")
return 0, errTestProbeNotExpected
}
err = c.resolveCacheMaxBytes(discardLogger(), probe)