diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-07-26 01:52:36 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-07-26 18:59:19 +0900 |
| commit | bd3fa53a552242b9d45a6743f16c31a8a2dca8ef (patch) | |
| tree | 59f942223bd7be064bc5681f639d090fd935b8ac /container/init_test.go | |
| parent | 625632c59391d73d32389e877179d3e023e224f2 (diff) | |
container: access test case by index in helper
This is more elegant and allows for much easier extension of the tests. Mountinfo is still serialised however due to libPaths nondeterminism.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/init_test.go')
| -rw-r--r-- | container/init_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/container/init_test.go b/container/init_test.go new file mode 100644 index 00000000..ad35b4cf --- /dev/null +++ b/container/init_test.go @@ -0,0 +1,43 @@ +package container_test + +import ( + "log" + "os" + "testing" + + "hakurei.app/command" + "hakurei.app/container" + "hakurei.app/internal" + "hakurei.app/internal/hlog" +) + +const ( + envDoCheck = "HAKUREI_TEST_DO_CHECK" +) + +var helperCommands []func(c command.Command) + +func TestMain(m *testing.M) { + container.TryArgv0(hlog.Output{}, hlog.Prepare, internal.InstallOutput) + + if os.Getenv(envDoCheck) == "1" { + c := command.New(os.Stderr, log.Printf, "helper", func(args []string) error { + log.SetFlags(0) + log.SetPrefix("helper: ") + return nil + }) + for _, f := range helperCommands { + f(c) + } + c.MustParse(os.Args[1:], func(err error) { + if err != nil { + log.Fatal(err.Error()) + } + }) + return + } + + os.Exit(m.Run()) +} + +func prepareHelper(c *container.Container) { c.Env = append(c.Env, envDoCheck+"=1") } |
