diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-07-28 01:04:29 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-07-28 01:04:29 +0900 |
| commit | 65fe09caf9bd8cbed9177022c765423885aed5be (patch) | |
| tree | 68600dafad417f2bc9bd2f246c51fdea4aad3fb3 /container/init_test.go | |
| parent | a1e5f020f48a65138c900961f856cf6b04833770 (diff) | |
container: check cancel signal delivery
This change also makes some parts of the test more robust.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/init_test.go')
| -rw-r--r-- | container/init_test.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/container/init_test.go b/container/init_test.go index ad35b4cf..6e99cc09 100644 --- a/container/init_test.go +++ b/container/init_test.go @@ -1,18 +1,24 @@ package container_test import ( + "context" "log" "os" "testing" + "time" "hakurei.app/command" "hakurei.app/container" "hakurei.app/internal" "hakurei.app/internal/hlog" + "hakurei.app/ldd" ) const ( envDoCheck = "HAKUREI_TEST_DO_CHECK" + + helperDefaultTimeout = 5 * time.Second + helperInnerPath = "/usr/bin/helper" ) var helperCommands []func(c command.Command) @@ -40,4 +46,24 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -func prepareHelper(c *container.Container) { c.Env = append(c.Env, envDoCheck+"=1") } +func helperNewContainerLibPaths(ctx context.Context, libPaths *[]string, args ...string) (c *container.Container) { + c = container.New(ctx, helperInnerPath, args...) + c.Env = append(c.Env, envDoCheck+"=1") + c.Bind(os.Args[0], helperInnerPath, 0) + + // in case test has cgo enabled + if entries, err := ldd.Exec(ctx, os.Args[0]); err != nil { + log.Fatalf("ldd: %v", err) + } else { + *libPaths = ldd.Path(entries) + } + for _, name := range *libPaths { + c.Bind(name, name, 0) + } + + return +} + +func helperNewContainer(ctx context.Context, args ...string) (c *container.Container) { + return helperNewContainerLibPaths(ctx, new([]string), args...) +} |
