1
0
forked from rosa/hakurei

internal/stub: move from container

This package solves a very specific stubbing use case, in a less than elegant manner.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-17 16:09:14 +09:00
parent 722989c682
commit bac583f89e
57 changed files with 60 additions and 57 deletions

View File

@@ -5,7 +5,7 @@ import (
"strings" "strings"
"testing" "testing"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestDecodeJSON(t *testing.T) { func TestDecodeJSON(t *testing.T) {

View File

@@ -6,7 +6,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestAutoEtcOp(t *testing.T) { func TestAutoEtcOp(t *testing.T) {

View File

@@ -7,7 +7,7 @@ import (
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -18,7 +18,7 @@ import (
"hakurei.app/container/seccomp" "hakurei.app/container/seccomp"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -9,7 +9,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
"hakurei.app/vfs" "hakurei.app/vfs"
) )

View File

@@ -10,7 +10,7 @@ import (
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/seccomp" "hakurei.app/container/seccomp"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestInitEntrypoint(t *testing.T) { func TestInitEntrypoint(t *testing.T) {

View File

@@ -8,7 +8,7 @@ import (
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestBindMountOp(t *testing.T) { func TestBindMountOp(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestMountDevOp(t *testing.T) { func TestMountDevOp(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestMkdirOp(t *testing.T) { func TestMkdirOp(t *testing.T) {

View File

@@ -6,7 +6,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestMountOverlayOp(t *testing.T) { func TestMountOverlayOp(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestTmpfileOp(t *testing.T) { func TestTmpfileOp(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestMountProcOp(t *testing.T) { func TestMountProcOp(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestRemountOp(t *testing.T) { func TestRemountOp(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestSymlinkOp(t *testing.T) { func TestSymlinkOp(t *testing.T) {

View File

@@ -6,7 +6,7 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestMountTmpfsOp(t *testing.T) { func TestMountTmpfsOp(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"syscall" "syscall"
"testing" "testing"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
"hakurei.app/vfs" "hakurei.app/vfs"
) )

View File

@@ -9,8 +9,8 @@ import (
"syscall" "syscall"
"testing" "testing"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/stub"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -7,10 +7,10 @@ import (
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub"
"hakurei.app/fhs" "hakurei.app/fhs"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/env" "hakurei.app/internal/env"
"hakurei.app/internal/stub"
) )
func TestPaths(t *testing.T) { func TestPaths(t *testing.T) {

View File

@@ -22,8 +22,8 @@ import (
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/seccomp" "hakurei.app/container/seccomp"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/stub"
"hakurei.app/internal/system" "hakurei.app/internal/system"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -9,8 +9,8 @@ import (
"testing" "testing"
"unsafe" "unsafe"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/stub"
) )
func TestHsu(t *testing.T) { func TestHsu(t *testing.T) {

View File

@@ -12,11 +12,11 @@ import (
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/seccomp" "hakurei.app/container/seccomp"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub"
"hakurei.app/ext" "hakurei.app/ext"
"hakurei.app/fhs" "hakurei.app/fhs"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/env" "hakurei.app/internal/env"
"hakurei.app/internal/stub"
) )
func TestShimEntrypoint(t *testing.T) { func TestShimEntrypoint(t *testing.T) {

View File

@@ -6,8 +6,8 @@ import (
"testing" "testing"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/stub"
) )
func TestSpAccountOp(t *testing.T) { func TestSpAccountOp(t *testing.T) {

View File

@@ -11,11 +11,11 @@ import (
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/seccomp" "hakurei.app/container/seccomp"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub"
"hakurei.app/fhs" "hakurei.app/fhs"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/dbus" "hakurei.app/internal/dbus"
"hakurei.app/internal/stub"
"hakurei.app/internal/system" "hakurei.app/internal/system"
) )

View File

@@ -5,11 +5,11 @@ import (
"testing" "testing"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/dbus" "hakurei.app/internal/dbus"
"hakurei.app/internal/helper" "hakurei.app/internal/helper"
"hakurei.app/internal/stub"
"hakurei.app/internal/system" "hakurei.app/internal/system"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -4,9 +4,9 @@ import (
"testing" "testing"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/pipewire" "hakurei.app/internal/pipewire"
"hakurei.app/internal/stub"
"hakurei.app/internal/system" "hakurei.app/internal/system"
) )

View File

@@ -9,9 +9,9 @@ import (
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/stub"
"hakurei.app/internal/system" "hakurei.app/internal/system"
) )

View File

@@ -5,10 +5,10 @@ import (
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub"
"hakurei.app/fhs" "hakurei.app/fhs"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/stub"
"hakurei.app/internal/system" "hakurei.app/internal/system"
) )

View File

@@ -5,10 +5,10 @@ import (
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/std" "hakurei.app/container/std"
"hakurei.app/container/stub"
"hakurei.app/fhs" "hakurei.app/fhs"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/stub"
"hakurei.app/internal/system" "hakurei.app/internal/system"
) )

View File

@@ -4,9 +4,9 @@ import (
"testing" "testing"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/stub"
"hakurei.app/internal/system" "hakurei.app/internal/system"
"hakurei.app/internal/wayland" "hakurei.app/internal/wayland"
) )

View File

@@ -5,9 +5,9 @@ import (
"testing" "testing"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/stub"
) )
func TestSpX11Op(t *testing.T) { func TestSpX11Op(t *testing.T) {

View File

@@ -8,8 +8,8 @@ import (
"testing" "testing"
"time" "time"
"hakurei.app/container/stub"
"hakurei.app/internal/pipewire" "hakurei.app/internal/pipewire"
"hakurei.app/internal/stub"
) )
func TestContext(t *testing.T) { func TestContext(t *testing.T) {

View File

@@ -14,9 +14,9 @@ import (
"unique" "unique"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
"hakurei.app/internal/stub"
) )
// testtoolBin is the container test tool binary made available to the // testtoolBin is the container test tool binary made available to the

View File

@@ -23,9 +23,9 @@ import (
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub"
"hakurei.app/fhs" "hakurei.app/fhs"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
"hakurei.app/internal/stub"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -13,8 +13,8 @@ import (
"testing/fstest" "testing/fstest"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
"hakurei.app/internal/stub"
) )
func TestTar(t *testing.T) { func TestTar(t *testing.T) {

View File

@@ -11,8 +11,8 @@ import (
"testing" "testing"
"time" "time"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/stub"
) )
func TestEntryData(t *testing.T) { func TestEntryData(t *testing.T) {

View File

@@ -13,9 +13,9 @@ import (
_ "unsafe" // for go:linkname _ "unsafe" // for go:linkname
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/store" "hakurei.app/internal/store"
"hakurei.app/internal/stub"
) )
// Made available here for direct validation of state entry files. // Made available here for direct validation of state entry files.

View File

@@ -4,7 +4,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestCallError(t *testing.T) { func TestCallError(t *testing.T) {

View File

@@ -9,11 +9,14 @@ var (
ErrCheck = errors.New("one or more arguments did not match") ErrCheck = errors.New("one or more arguments did not match")
) )
// UniqueError is an error that only equivalates to other [UniqueError] with the same magic value. // UniqueError is an error that only equivalates to another [UniqueError] with
// the same magic value.
type UniqueError uintptr type UniqueError uintptr
func (e UniqueError) Error() string { func (e UniqueError) Error() string {
return "unique error " + strconv.FormatUint(uint64(e), 10) + " injected by the test suite" return "unique error " +
strconv.FormatUint(uint64(e), 10) +
" injected by the test suite"
} }
func (e UniqueError) Is(target error) bool { func (e UniqueError) Is(target error) bool {

View File

@@ -5,7 +5,7 @@ import (
"syscall" "syscall"
"testing" "testing"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestUniqueError(t *testing.T) { func TestUniqueError(t *testing.T) {

View File

@@ -4,12 +4,12 @@ import (
"testing" "testing"
_ "unsafe" // for go:linkname _ "unsafe" // for go:linkname
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
// Made available here to check panic recovery behaviour. // Made available here to check panic recovery behaviour.
// //
//go:linkname handleExitNew hakurei.app/container/stub.handleExitNew //go:linkname handleExitNew hakurei.app/internal/stub.handleExitNew
func handleExitNew(t testing.TB) func handleExitNew(t testing.TB)
// overrideTFailNow overrides the Fail and FailNow method. // overrideTFailNow overrides the Fail and FailNow method.

View File

@@ -1,5 +1,5 @@
// Package stub provides function call level stubbing and validation // Package stub provides function call level stubbing and validation for library
// for library functions that are impossible to check otherwise. // functions that are impossible to check otherwise.
package stub package stub
import ( import (

View File

@@ -5,9 +5,9 @@ import (
"syscall" "syscall"
"testing" "testing"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/stub"
) )
func TestACLUpdateOp(t *testing.T) { func TestACLUpdateOp(t *testing.T) {

View File

@@ -9,10 +9,10 @@ import (
"syscall" "syscall"
"testing" "testing"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/dbus" "hakurei.app/internal/dbus"
"hakurei.app/internal/helper" "hakurei.app/internal/helper"
"hakurei.app/internal/stub"
) )
func TestDBusProxyOp(t *testing.T) { func TestDBusProxyOp(t *testing.T) {

View File

@@ -10,11 +10,11 @@ import (
"unsafe" "unsafe"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/dbus" "hakurei.app/internal/dbus"
"hakurei.app/internal/pipewire" "hakurei.app/internal/pipewire"
"hakurei.app/internal/stub"
"hakurei.app/internal/xcb" "hakurei.app/internal/xcb"
) )

View File

@@ -3,8 +3,8 @@ package system
import ( import (
"testing" "testing"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/stub"
) )
func TestHardlinkOp(t *testing.T) { func TestHardlinkOp(t *testing.T) {

View File

@@ -4,7 +4,7 @@ import (
"os" "os"
"testing" "testing"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestMkdirOp(t *testing.T) { func TestMkdirOp(t *testing.T) {

View File

@@ -8,9 +8,9 @@ import (
"testing" "testing"
"time" "time"
"hakurei.app/container/stub"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/pipewire" "hakurei.app/internal/pipewire"
"hakurei.app/internal/stub"
) )
func TestPipeWireOp(t *testing.T) { func TestPipeWireOp(t *testing.T) {

View File

@@ -9,8 +9,8 @@ import (
"testing" "testing"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/stub"
"hakurei.app/internal/xcb" "hakurei.app/internal/xcb"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -4,8 +4,8 @@ import (
"os" "os"
"testing" "testing"
"hakurei.app/container/stub"
"hakurei.app/internal/acl" "hakurei.app/internal/acl"
"hakurei.app/internal/stub"
) )
func TestWaylandOp(t *testing.T) { func TestWaylandOp(t *testing.T) {

View File

@@ -3,8 +3,8 @@ package system
import ( import (
"testing" "testing"
"hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/stub"
"hakurei.app/internal/xcb" "hakurei.app/internal/xcb"
) )

View File

@@ -7,7 +7,7 @@ import (
"syscall" "syscall"
"testing" "testing"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
) )
func TestError(t *testing.T) { func TestError(t *testing.T) {

View File

@@ -10,7 +10,7 @@ import (
"testing" "testing"
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
"hakurei.app/message" "hakurei.app/message"
) )

View File

@@ -8,7 +8,7 @@ import (
"syscall" "syscall"
"testing" "testing"
"hakurei.app/container/stub" "hakurei.app/internal/stub"
"hakurei.app/message" "hakurei.app/message"
) )