container/stub: export stub helpers
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 1m53s
Test / Hakurei (push) Successful in 3m18s
Test / Sandbox (race detector) (push) Successful in 3m40s
Test / Hpkg (push) Successful in 3m35s
Test / Hakurei (race detector) (push) Successful in 5m19s
Test / Flake checks (push) Successful in 1m39s

These are very useful in many packages containing relatively large amount of code making calls to difficult or impossible to stub functions.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-08-31 23:11:25 +09:00
parent b489a3bba1
commit 49600a6f46
23 changed files with 3808 additions and 3247 deletions

View File

@@ -8,6 +8,7 @@ import (
"syscall"
"testing"
"hakurei.app/container/stub"
"hakurei.app/container/vfs"
)
@@ -30,8 +31,8 @@ func TestMessageFromError(t *testing.T) {
{"path", &os.PathError{
Op: "mount",
Path: "/sysroot",
Err: errUnique,
}, "cannot mount /sysroot: unique error injected by the test suite", true},
Err: stub.UniqueError(0xdeadbeef),
}, "cannot mount /sysroot: unique error 3735928559 injected by the test suite", true},
{"absolute", &AbsoluteError{"etc/mtab"},
`path "etc/mtab" is not absolute`, true},
@@ -48,7 +49,7 @@ func TestMessageFromError(t *testing.T) {
{"tmpfs", TmpfsSizeError(-1),
"tmpfs size -1 out of bounds", true},
{"unsupported", errUnique, zeroString, false},
{"unsupported", stub.UniqueError(0xdeadbeef), zeroString, false},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
@@ -144,10 +145,10 @@ func TestErrnoFallback(t *testing.T) {
Err: syscall.ETIMEDOUT,
}, syscall.ETIMEDOUT, nil},
{"fallback", errUnique, 0, &os.PathError{
{"fallback", stub.UniqueError(0xcafebabe), 0, &os.PathError{
Op: "fallback",
Path: "/proc/nonexistent",
Err: errUnique,
Err: stub.UniqueError(0xcafebabe),
}},
}
for _, tc := range testCases {