aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-05 00:47:39 +0900
committerOphestra <cat@gensokyo.uk>2026-03-05 00:47:39 +0900
commit7e2f13fa1bcf4e5e7b8971f3914873044e5ea5e7 (patch)
tree874287b0ac39dcd8289784790319ddc2161158e1
parent97448e210404cfceae7243043c222acac4297a58 (diff)
internal/rosa: cure checks
This cures all presets if a cache directory is supplied and verbose is set. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--internal/rosa/all_test.go3
-rw-r--r--internal/rosa/rosa_test.go93
2 files changed, 96 insertions, 0 deletions
diff --git a/internal/rosa/all_test.go b/internal/rosa/all_test.go
index 7187c25d..2791402b 100644
--- a/internal/rosa/all_test.go
+++ b/internal/rosa/all_test.go
@@ -2,6 +2,9 @@ package rosa
import "testing"
+// PresetEnd is the total PArtifact count exported for testing.
+const PresetEnd = _presetEnd
+
func TestLoad(t *testing.T) {
t.Parallel()
diff --git a/internal/rosa/rosa_test.go b/internal/rosa/rosa_test.go
new file mode 100644
index 00000000..b4578cf3
--- /dev/null
+++ b/internal/rosa/rosa_test.go
@@ -0,0 +1,93 @@
+package rosa_test
+
+import (
+ "context"
+ "log"
+ "os"
+ "os/signal"
+ "sync"
+ "syscall"
+ "testing"
+
+ "hakurei.app/container"
+ "hakurei.app/container/check"
+ "hakurei.app/internal/pkg"
+ "hakurei.app/internal/rosa"
+ "hakurei.app/message"
+)
+
+var (
+ // skipBuildTest caches whether build tests are skipped.
+ skipBuildTest bool
+ // buildTestCache is populated by getCache and must not be accessed directly.
+ buildTestCache *pkg.Cache
+ // buildTestCacheCancel cancels buildTestCache.
+ buildTestCacheCancel context.CancelFunc
+ // buildTestCacheOnce synchronises access to buildTestCache.
+ buildTestCacheOnce sync.Once
+)
+
+func TestMain(m *testing.M) {
+ container.TryArgv0(nil)
+
+ code := m.Run()
+ if buildTestCache != nil {
+ buildTestCacheCancel()
+ buildTestCache.Close()
+ }
+ os.Exit(code)
+}
+
+func getCache(t *testing.T) *pkg.Cache {
+ t.Helper()
+ const env = "ROSA_BUILD_TEST_CACHE_DIR"
+
+ if !testing.Verbose() {
+ t.Skip("verbose flag not set")
+ }
+
+ buildTestCacheOnce.Do(func() {
+ if p, ok := os.LookupEnv(env); !ok {
+ skipBuildTest = true
+ return
+ } else if a, err := check.NewAbs(p); err != nil {
+ t.Fatal(err)
+ } else {
+ var ctx context.Context
+ ctx, buildTestCacheCancel = signal.NotifyContext(context.Background(),
+ syscall.SIGINT, syscall.SIGTERM)
+
+ msg := message.New(log.New(os.Stderr, "rosa: ", 0))
+ msg.SwapVerbose(true)
+
+ if buildTestCache, err = pkg.Open(ctx, msg, 0, a); err != nil {
+ t.Fatal(err)
+ }
+ }
+ })
+
+ if skipBuildTest {
+ t.Skip(env + " not set")
+ }
+ return buildTestCache
+}
+
+func TestCureAll(t *testing.T) {
+ cache := getCache(t)
+ t.Parallel()
+
+ for i := range rosa.PresetEnd {
+ p := rosa.PArtifact(i)
+ meta := rosa.GetMetadata(p)
+ a := rosa.Std.Load(p)
+ t.Run(meta.Name, func(t *testing.T) {
+ t.Parallel()
+
+ if pathname, _, err := cache.Cure(a); err != nil {
+ t.Fatal(err)
+ } else {
+ t.Log(pathname)
+ }
+ })
+ }
+}