diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-04-16 15:43:06 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-04-16 15:59:34 +0900 |
| commit | 136bc0917be7c02b818bfc8d4d54ec8ffbc8d21b (patch) | |
| tree | 08fec4ac2d6beb05c4c536497cd88678feb419e1 /cmd/mbf/cache_test.go | |
| parent | d6b082dd0b162197c06b8ac06279024c64ceb0e3 (diff) | |
cmd/mbf: optionally open cache
Some commands do not require the cache. This change also makes acquisition of locked cache cancelable.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd/mbf/cache_test.go')
| -rw-r--r-- | cmd/mbf/cache_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cmd/mbf/cache_test.go b/cmd/mbf/cache_test.go new file mode 100644 index 00000000..0f036542 --- /dev/null +++ b/cmd/mbf/cache_test.go @@ -0,0 +1,38 @@ +package main + +import ( + "context" + "log" + "os" + "testing" + + "hakurei.app/internal/pkg" + "hakurei.app/message" +) + +func TestCache(t *testing.T) { + t.Parallel() + + cm := cache{ + ctx: context.Background(), + msg: message.New(log.New(os.Stderr, "check: ", 0)), + base: t.TempDir(), + + hostAbstract: true, idle: true, + } + defer cm.Close() + cm.Close() + + if err := cm.open(); err != nil { + t.Fatalf("open: error = %v", err) + } + if err := cm.open(); err != os.ErrInvalid { + t.Errorf("(duplicate) open: error = %v", err) + } + + if err := cm.Do(func(cache *pkg.Cache) error { + return cache.Scrub(0) + }); err != nil { + t.Errorf("Scrub: error = %v", err) + } +} |
