internal/pkg: implement exec artifact
All checks were successful
Test / Create distribution (push) Successful in 52s
Test / Sandbox (push) Successful in 2m35s
Test / Hakurei (push) Successful in 3m41s
Test / ShareFS (push) Successful in 3m46s
Test / Hpkg (push) Successful in 4m30s
Test / Sandbox (race detector) (push) Successful in 4m57s
Test / Hakurei (race detector) (push) Successful in 5m57s
Test / Flake checks (push) Successful in 1m43s
All checks were successful
Test / Create distribution (push) Successful in 52s
Test / Sandbox (push) Successful in 2m35s
Test / Hakurei (push) Successful in 3m41s
Test / ShareFS (push) Successful in 3m46s
Test / Hpkg (push) Successful in 4m30s
Test / Sandbox (race detector) (push) Successful in 4m57s
Test / Hakurei (race detector) (push) Successful in 5m57s
Test / Flake checks (push) Successful in 1m43s
This runs a program in a container environment. Artifacts can be made available to the container, they are cured concurrently and mounted in order. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
103
internal/pkg/testdata/main.go
vendored
Normal file
103
internal/pkg/testdata/main.go
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
//go:build testtool
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
|
||||
"hakurei.app/container/fhs"
|
||||
"hakurei.app/container/vfs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
log.SetPrefix("testtool: ")
|
||||
|
||||
if wantArgs := []string{"testtool"}; !slices.Equal(os.Args, wantArgs) {
|
||||
log.Fatalf("Args: %q, want %q", os.Args, wantArgs)
|
||||
}
|
||||
if wantEnv := []string{
|
||||
"HAKUREI_TEST=1",
|
||||
}; !slices.Equal(wantEnv, os.Environ()) {
|
||||
log.Fatalf("Environ: %q, want %q", os.Environ(), wantEnv)
|
||||
}
|
||||
const wantExec = "/opt/bin/testtool"
|
||||
if got, err := os.Executable(); err != nil {
|
||||
log.Fatalf("Executable: error = %v", err)
|
||||
} else if got != wantExec {
|
||||
log.Fatalf("Executable: %q, want %q", got, wantExec)
|
||||
}
|
||||
|
||||
var m *vfs.MountInfo
|
||||
if f, err := os.Open(fhs.Proc + "self/mountinfo"); err != nil {
|
||||
log.Fatalf("Open: error = %v", err)
|
||||
} else {
|
||||
err = vfs.NewMountInfoDecoder(f).Decode(&m)
|
||||
closeErr := f.Close()
|
||||
if err != nil {
|
||||
log.Fatalf("Decode: error = %v", err)
|
||||
}
|
||||
if closeErr != nil {
|
||||
log.Fatalf("Close: error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
log.Println(m)
|
||||
if m.Root != "/sysroot" || m.Target != "/" {
|
||||
log.Fatal("unexpected root mount entry")
|
||||
}
|
||||
next := func() { m = m.Next; log.Println(m) }
|
||||
|
||||
next()
|
||||
if path.Base(m.Root) != "OLBgp1GsljhM2TJ-sbHjaiH9txEUvgdDTAzHv2P24donTt6_529l-9Ua0vFImLlb" {
|
||||
log.Fatal("unexpected file artifact checksum")
|
||||
}
|
||||
|
||||
next()
|
||||
if path.Base(m.Root) != "MGWmEfjut2QE2xPJwTsmUzpff4BN_FEnQ7T0j7gvUCCiugJQNwqt9m151fm9D1yU" {
|
||||
log.Fatal("unexpected artifact checksum")
|
||||
}
|
||||
|
||||
next() // testtool artifact
|
||||
|
||||
next()
|
||||
if path.Base(m.Root) !=
|
||||
"oHuqV7p0v1Vd8IdAzjyYM8sfCS0P2LR5tfv5cb6Gbf2ZWUm8Ec-7hYPJ_qr183m7" || m.Target != "/work" {
|
||||
log.Fatal("unexpected work mount entry")
|
||||
}
|
||||
|
||||
next()
|
||||
if path.Base(m.Root) !=
|
||||
"oHuqV7p0v1Vd8IdAzjyYM8sfCS0P2LR5tfv5cb6Gbf2ZWUm8Ec-7hYPJ_qr183m7" || m.Target != "/tmp" {
|
||||
log.Fatal("unexpected temp mount entry")
|
||||
}
|
||||
|
||||
next()
|
||||
if m.Root != "/" || m.Target != "/proc" || m.Source != "proc" || m.FsType != "proc" {
|
||||
log.Fatal("unexpected proc mount entry")
|
||||
}
|
||||
|
||||
next()
|
||||
if m.Root != "/" || m.Target != "/dev" || m.Source != "devtmpfs" || m.FsType != "tmpfs" {
|
||||
log.Fatal("unexpected dev mount entry")
|
||||
}
|
||||
|
||||
for i := 0; i < 9; i++ { // private /dev entries
|
||||
next()
|
||||
}
|
||||
|
||||
if m.Next != nil {
|
||||
log.Println("unexpected extra mount entries")
|
||||
for m.Next != nil {
|
||||
next()
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := os.WriteFile("check", []byte{0}, 0400); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user