container: move integration test helpers
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m13s
Test / Hpkg (push) Successful in 4m1s
Test / Sandbox (race detector) (push) Successful in 4m42s
Test / Hakurei (race detector) (push) Successful in 5m8s
Test / Hakurei (push) Successful in 42s
Test / Flake checks (push) Successful in 1m38s
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m13s
Test / Hpkg (push) Successful in 4m1s
Test / Sandbox (race detector) (push) Successful in 4m42s
Test / Hakurei (race detector) (push) Successful in 5m8s
Test / Hakurei (push) Successful in 42s
Test / Flake checks (push) Successful in 1m38s
With the new instrumentation it is now possible to run init code outside integration tests. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
afe23600d2
commit
141a18999f
@ -14,12 +14,16 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"hakurei.app/command"
|
"hakurei.app/command"
|
||||||
"hakurei.app/container"
|
"hakurei.app/container"
|
||||||
"hakurei.app/container/seccomp"
|
"hakurei.app/container/seccomp"
|
||||||
"hakurei.app/container/vfs"
|
"hakurei.app/container/vfs"
|
||||||
"hakurei.app/hst"
|
"hakurei.app/hst"
|
||||||
|
"hakurei.app/internal"
|
||||||
|
"hakurei.app/internal/hlog"
|
||||||
|
"hakurei.app/ldd"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -510,3 +514,61 @@ func init() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
envDoCheck = "HAKUREI_TEST_DO_CHECK"
|
||||||
|
|
||||||
|
helperDefaultTimeout = 5 * time.Second
|
||||||
|
helperInnerPath = "/usr/bin/helper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
absHelperInnerPath = container.MustAbs(helperInnerPath)
|
||||||
|
)
|
||||||
|
|
||||||
|
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 helperNewContainerLibPaths(ctx context.Context, libPaths *[]*container.Absolute, args ...string) (c *container.Container) {
|
||||||
|
c = container.NewCommand(ctx, absHelperInnerPath, "helper", args...)
|
||||||
|
c.Env = append(c.Env, envDoCheck+"=1")
|
||||||
|
c.Bind(container.MustAbs(os.Args[0]), absHelperInnerPath, 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([]*container.Absolute), args...)
|
||||||
|
}
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
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 (
|
|
||||||
absHelperInnerPath = container.MustAbs(helperInnerPath)
|
|
||||||
)
|
|
||||||
|
|
||||||
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 helperNewContainerLibPaths(ctx context.Context, libPaths *[]*container.Absolute, args ...string) (c *container.Container) {
|
|
||||||
c = container.NewCommand(ctx, absHelperInnerPath, "helper", args...)
|
|
||||||
c.Env = append(c.Env, envDoCheck+"=1")
|
|
||||||
c.Bind(container.MustAbs(os.Args[0]), absHelperInnerPath, 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([]*container.Absolute), args...)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user