From adbf2f2f0d0a4ae2797defd623223b5860c9ddfb Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Sun, 4 Oct 2026 16:26:38 +0000 Subject: [PATCH] Test the cache config the handlers build from cache_max_bytes With cache_max_bytes omitted the cache must work out the default limit, with an explicit 0 the disk cache must be off, and an explicit positive value must reach the cache unchanged. newCacheConfig does not exist yet, so this commit does not compile; the next one adds it. Model: opus-5-5 --- .../handlers/cache_max_bytes_internal_test.go | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/internal/handlers/cache_max_bytes_internal_test.go b/internal/handlers/cache_max_bytes_internal_test.go index 0802216..af0a8ab 100644 --- a/internal/handlers/cache_max_bytes_internal_test.go +++ b/internal/handlers/cache_max_bytes_internal_test.go @@ -13,6 +13,79 @@ import ( "sneak.berlin/go/pixa/internal/logger" ) +// TestNewCacheConfigFromCacheMaxBytes checks the cache configuration +// built from cache_max_bytes: omitted, the cache works out the default +// limit; 0 turns the disk cache off; a positive value is the limit, +// unchanged. +func TestNewCacheConfigFromCacheMaxBytes(t *testing.T) { + t.Parallel() + + const oneGiB = 1 << 30 + + cases := []struct { + name string + cacheMaxBytes int64 + cacheMaxBytesExplicit bool + wantMaxBytes int64 + wantUseDefaultMaxBytes bool + wantDisableDiskCache bool + }{ + { + name: "cache_max_bytes omitted", + cacheMaxBytes: 0, + cacheMaxBytesExplicit: false, + wantMaxBytes: 0, + wantUseDefaultMaxBytes: true, + wantDisableDiskCache: false, + }, + { + name: "cache_max_bytes: 0", + cacheMaxBytes: 0, + cacheMaxBytesExplicit: true, + wantMaxBytes: 0, + wantUseDefaultMaxBytes: false, + wantDisableDiskCache: true, + }, + { + name: "cache_max_bytes: 1 GiB", + cacheMaxBytes: oneGiB, + cacheMaxBytesExplicit: true, + wantMaxBytes: oneGiB, + wantUseDefaultMaxBytes: false, + wantDisableDiskCache: false, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + cfg := &config.Config{ + CacheMaxBytes: tc.cacheMaxBytes, + CacheMaxBytesExplicit: tc.cacheMaxBytesExplicit, + } + + got := newCacheConfig(cfg, nil) + t.Logf("MaxBytes = %d, UseDefaultMaxBytes = %v, DisableDiskCache = %v", + got.MaxBytes, got.UseDefaultMaxBytes, got.DisableDiskCache) + + if got.MaxBytes != tc.wantMaxBytes { + t.Errorf("MaxBytes = %d, want %d", got.MaxBytes, tc.wantMaxBytes) + } + + if got.UseDefaultMaxBytes != tc.wantUseDefaultMaxBytes { + t.Errorf("UseDefaultMaxBytes = %v, want %v", + got.UseDefaultMaxBytes, tc.wantUseDefaultMaxBytes) + } + + if got.DisableDiskCache != tc.wantDisableDiskCache { + t.Errorf("DisableDiskCache = %v, want %v", + got.DisableDiskCache, tc.wantDisableDiskCache) + } + }) + } +} + // TestDiskCacheOffOnlyForExplicitZeroCacheMaxBytes starts the handlers // once with cache_max_bytes omitted and once with cache_max_bytes: 0, // and checks by whether the cache directories were created that the