diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-07-25 00:43:22 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-07-25 00:45:10 +0900 |
| commit | e71ae3b8c5b4a8f103a078783fef2f56ee5450a2 (patch) | |
| tree | e6b7a87006563da8c360ca248e261a7fe7e2820f /helper | |
| parent | 9d7a19d162e7003ce89804f00c526b77b2328baa (diff) | |
container: remove custom cmd initialisation
This part of the interface is very unintuitive and only used for testing, even in testing it is inelegant and can be done better.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'helper')
| -rw-r--r-- | helper/container_test.go | 15 | ||||
| -rw-r--r-- | helper/helper_test.go | 1 | ||||
| -rw-r--r-- | helper/stub.go | 2 | ||||
| -rw-r--r-- | helper/stub_test.go | 10 |
4 files changed, 10 insertions, 18 deletions
diff --git a/helper/container_test.go b/helper/container_test.go index 71c25bd1..f5dc1aaa 100644 --- a/helper/container_test.go +++ b/helper/container_test.go @@ -4,13 +4,10 @@ import ( "context" "io" "os" - "os/exec" "testing" "hakurei.app/container" "hakurei.app/helper" - "hakurei.app/internal" - "hakurei.app/internal/hlog" ) func TestContainer(t *testing.T) { @@ -36,20 +33,8 @@ func TestContainer(t *testing.T) { testHelper(t, func(ctx context.Context, setOutput func(stdoutP, stderrP *io.Writer), stat bool) helper.Helper { return helper.New(ctx, os.Args[0], argsWt, stat, argF, func(z *container.Container) { setOutput(&z.Stdout, &z.Stderr) - z.CommandContext = func(ctx context.Context) (cmd *exec.Cmd) { - return exec.CommandContext(ctx, os.Args[0], "-test.v", - "-test.run=TestHelperInit", "--", "init") - } z.Bind("/", "/", 0).Proc("/proc").Dev("/dev") }, nil) }) }) } - -func TestHelperInit(t *testing.T) { - if len(os.Args) != 5 || os.Args[4] != "init" { - return - } - container.SetOutput(hlog.Output{}) - container.Init(hlog.Prepare, func(bool) { internal.InstallOutput(false) }) -} diff --git a/helper/helper_test.go b/helper/helper_test.go index cc6f892e..ef4b6bca 100644 --- a/helper/helper_test.go +++ b/helper/helper_test.go @@ -38,7 +38,6 @@ func argF(argsFd, statFd int) []string { func argFChecked(argsFd, statFd int) (args []string) { args = make([]string, 0, 6) - args = append(args, "-test.run=TestHelperStub", "--") if argsFd > -1 { args = append(args, "--args", strconv.Itoa(argsFd)) } diff --git a/helper/stub.go b/helper/stub.go index bd0e1b52..852930fb 100644 --- a/helper/stub.go +++ b/helper/stub.go @@ -25,7 +25,7 @@ func InternalHelperStub() { sp = v } - genericStub(flagRestoreFiles(3, ap, sp)) + genericStub(flagRestoreFiles(1, ap, sp)) os.Exit(0) } diff --git a/helper/stub_test.go b/helper/stub_test.go index e496f143..dc057ac1 100644 --- a/helper/stub_test.go +++ b/helper/stub_test.go @@ -1,9 +1,17 @@ package helper_test import ( + "os" "testing" + "hakurei.app/container" "hakurei.app/helper" + "hakurei.app/internal" + "hakurei.app/internal/hlog" ) -func TestHelperStub(t *testing.T) { helper.InternalHelperStub() } +func TestMain(m *testing.M) { + container.TryArgv0(hlog.Output{}, hlog.Prepare, internal.InstallOutput) + helper.InternalHelperStub() + os.Exit(m.Run()) +} |
