aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/container_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-07-25 00:43:22 +0900
committerOphestra <cat@gensokyo.uk>2025-07-25 00:45:10 +0900
commite71ae3b8c5b4a8f103a078783fef2f56ee5450a2 (patch)
treee6b7a87006563da8c360ca248e261a7fe7e2820f /container/container_test.go
parent9d7a19d162e7003ce89804f00c526b77b2328baa (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 'container/container_test.go')
-rw-r--r--container/container_test.go26
1 files changed, 6 insertions, 20 deletions
diff --git a/container/container_test.go b/container/container_test.go
index 4ded1fb5..80243190 100644
--- a/container/container_test.go
+++ b/container/container_test.go
@@ -6,7 +6,6 @@ import (
"encoding/gob"
"log"
"os"
- "os/exec"
"strings"
"syscall"
"testing"
@@ -26,6 +25,11 @@ const (
ignoreV = -1
)
+func TestMain(m *testing.M) {
+ container.TryArgv0(hlog.Output{}, hlog.Prepare, internal.InstallOutput)
+ os.Exit(m.Run())
+}
+
func TestContainer(t *testing.T) {
{
oldVerbose := hlog.Load()
@@ -96,7 +100,6 @@ func TestContainer(t *testing.T) {
c.Uid = 1000
c.Gid = 100
c.Hostname = tc.host
- c.CommandContext = commandContext
c.Stdout, c.Stderr = os.Stdout, os.Stderr
c.Ops = tc.ops
c.SeccompRules = tc.rules
@@ -121,11 +124,7 @@ func TestContainer(t *testing.T) {
Place("/etc/hostname", []byte(c.Args[5]))
// in case test has cgo enabled
var libPaths []string
- if entries, err := ldd.ExecFilter(ctx,
- commandContext,
- func(v []byte) []byte {
- return bytes.SplitN(v, []byte("TestHelperInit\n"), 2)[1]
- }, os.Args[0]); err != nil {
+ if entries, err := ldd.Exec(ctx, os.Args[0]); err != nil {
log.Fatalf("ldd: %v", err)
} else {
libPaths = ldd.Path(entries)
@@ -197,14 +196,6 @@ func TestContainerString(t *testing.T) {
}
}
-func TestHelperInit(t *testing.T) {
- if len(os.Args) != 5 || os.Args[4] != "init" {
- return
- }
- container.SetOutput(hlog.Output{})
- container.Init(hlog.Prepare, internal.InstallOutput)
-}
-
func TestHelperCheckContainer(t *testing.T) {
if len(os.Args) != 6 || os.Args[4] != "check" {
return
@@ -274,8 +265,3 @@ func TestHelperCheckContainer(t *testing.T) {
}
})
}
-
-func commandContext(ctx context.Context) *exec.Cmd {
- return exec.CommandContext(ctx, os.Args[0], "-test.v",
- "-test.run=TestHelperInit", "--", "init")
-}