From 136bc0917be7c02b818bfc8d4d54ec8ffbc8d21b Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 16 Apr 2026 15:43:06 +0900 Subject: 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 --- cmd/mbf/cache_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cmd/mbf/cache_test.go (limited to 'cmd/mbf/cache_test.go') 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) + } +} -- cgit v1.3.1