treewide: parallel tests
All checks were successful
Test / Create distribution (push) Successful in 25s
Test / Hakurei (push) Successful in 44s
Test / Sandbox (push) Successful in 41s
Test / Hakurei (race detector) (push) Successful in 44s
Test / Sandbox (race detector) (push) Successful in 41s
Test / Hpkg (push) Successful in 41s
Test / Flake checks (push) Successful in 1m24s
All checks were successful
Test / Create distribution (push) Successful in 25s
Test / Hakurei (push) Successful in 44s
Test / Sandbox (push) Successful in 41s
Test / Hakurei (race detector) (push) Successful in 44s
Test / Sandbox (race detector) (push) Successful in 41s
Test / Hpkg (push) Successful in 41s
Test / Flake checks (push) Successful in 1m24s
Most tests already had no global state, however parallel was never enabled. This change enables it for all applicable tests. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -10,7 +10,10 @@ import (
|
||||
)
|
||||
|
||||
func TestAutoEtcOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("nonrepeatable", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
wantErr := OpRepeatError("autoetc")
|
||||
if err := (&AutoEtcOp{Prefix: "81ceabb30d37bbdb3868004629cb84e9"}).apply(&setupState{nonrepeatable: nrAutoEtc}, nil); !errors.Is(err, wantErr) {
|
||||
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
||||
@@ -280,6 +283,7 @@ func TestAutoEtcOp(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("host path rel", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
op := &AutoEtcOp{Prefix: "048090b6ed8f9ebb10e275ff5d8c0659"}
|
||||
wantHostPath := "/etc/.host/048090b6ed8f9ebb10e275ff5d8c0659"
|
||||
wantHostRel := ".host/048090b6ed8f9ebb10e275ff5d8c0659"
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
func TestAutoRootOp(t *testing.T) {
|
||||
t.Run("nonrepeatable", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
wantErr := OpRepeatError("autoroot")
|
||||
if err := new(AutoRootOp).apply(&setupState{nonrepeatable: nrAutoRoot}, nil); !errors.Is(err, wantErr) {
|
||||
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
||||
@@ -180,6 +181,8 @@ func TestAutoRootOp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIsAutoRootBindable(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
want bool
|
||||
@@ -196,6 +199,7 @@ func TestIsAutoRootBindable(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
var msg message.Msg
|
||||
if tc.log {
|
||||
msg = &kstub{nil, stub.New(t, func(s *stub.Stub[syscallDispatcher]) syscallDispatcher { panic("unreachable") }, stub.Expect{Calls: []stub.Call{
|
||||
|
||||
@@ -3,6 +3,8 @@ package container
|
||||
import "testing"
|
||||
|
||||
func TestCapToIndex(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
cap uintptr
|
||||
@@ -14,6 +16,7 @@ func TestCapToIndex(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := capToIndex(tc.cap); got != tc.want {
|
||||
t.Errorf("capToIndex: %#x, want %#x", got, tc.want)
|
||||
}
|
||||
@@ -22,6 +25,8 @@ func TestCapToIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCapToMask(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
cap uintptr
|
||||
@@ -33,6 +38,7 @@ func TestCapToMask(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := capToMask(tc.cap); got != tc.want {
|
||||
t.Errorf("capToMask: %#x, want %#x", got, tc.want)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ import (
|
||||
func unsafeAbs(_ string) *Absolute
|
||||
|
||||
func TestAbsoluteError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -27,8 +29,8 @@ func TestAbsoluteError(t *testing.T) {
|
||||
}{
|
||||
{"EINVAL", new(AbsoluteError), syscall.EINVAL, true},
|
||||
{"not EINVAL", new(AbsoluteError), syscall.EBADE, false},
|
||||
{"ne val", new(AbsoluteError), &AbsoluteError{"etc"}, false},
|
||||
{"equals", &AbsoluteError{"etc"}, &AbsoluteError{"etc"}, true},
|
||||
{"ne val", new(AbsoluteError), &AbsoluteError{Pathname: "etc"}, false},
|
||||
{"equals", &AbsoluteError{Pathname: "etc"}, &AbsoluteError{Pathname: "etc"}, true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
@@ -38,14 +40,18 @@ func TestAbsoluteError(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("string", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
want := `path "etc" is not absolute`
|
||||
if got := (&AbsoluteError{"etc"}).Error(); got != want {
|
||||
if got := (&AbsoluteError{Pathname: "etc"}).Error(); got != want {
|
||||
t.Errorf("Error: %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewAbs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -54,12 +60,14 @@ func TestNewAbs(t *testing.T) {
|
||||
wantErr error
|
||||
}{
|
||||
{"good", "/etc", MustAbs("/etc"), nil},
|
||||
{"not absolute", "etc", nil, &AbsoluteError{"etc"}},
|
||||
{"zero", "", nil, &AbsoluteError{""}},
|
||||
{"not absolute", "etc", nil, &AbsoluteError{Pathname: "etc"}},
|
||||
{"zero", "", nil, &AbsoluteError{Pathname: ""}},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got, err := NewAbs(tc.pathname)
|
||||
if !reflect.DeepEqual(got, tc.want) {
|
||||
t.Errorf("NewAbs: %#v, want %#v", got, tc.want)
|
||||
@@ -71,6 +79,8 @@ func TestNewAbs(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("must", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
wantPanic := `path "etc" is not absolute`
|
||||
|
||||
@@ -85,6 +95,8 @@ func TestNewAbs(t *testing.T) {
|
||||
|
||||
func TestAbsoluteString(t *testing.T) {
|
||||
t.Run("passthrough", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
pathname := "/etc"
|
||||
if got := unsafeAbs(pathname).String(); got != pathname {
|
||||
t.Errorf("String: %q, want %q", got, pathname)
|
||||
@@ -92,6 +104,8 @@ func TestAbsoluteString(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("zero", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
wantPanic := "attempted use of zero Absolute"
|
||||
|
||||
@@ -105,6 +119,8 @@ func TestAbsoluteString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAbsoluteIs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
a, v *Absolute
|
||||
@@ -120,6 +136,8 @@ func TestAbsoluteIs(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if got := tc.a.Is(tc.v); got != tc.want {
|
||||
t.Errorf("Is: %v, want %v", got, tc.want)
|
||||
}
|
||||
@@ -133,6 +151,8 @@ type sCheck struct {
|
||||
}
|
||||
|
||||
func TestCodecAbsolute(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
a *Absolute
|
||||
@@ -153,7 +173,7 @@ func TestCodecAbsolute(t *testing.T) {
|
||||
|
||||
`"/etc"`, `{"val":"/etc","magic":3236757504}`},
|
||||
{"not absolute", nil,
|
||||
&AbsoluteError{"etc"},
|
||||
&AbsoluteError{Pathname: "etc"},
|
||||
"\t\x7f\x05\x01\x02\xff\x82\x00\x00\x00\a\xff\x80\x00\x03etc",
|
||||
",\xff\x83\x03\x01\x01\x06sCheck\x01\xff\x84\x00\x01\x02\x01\bPathname\x01\xff\x80\x00\x01\x05Magic\x01\x04\x00\x00\x00\t\x7f\x05\x01\x02\xff\x82\x00\x00\x00\x0f\xff\x84\x01\x03etc\x01\xfb\x01\x81\xda\x00\x00\x00",
|
||||
|
||||
@@ -167,13 +187,18 @@ func TestCodecAbsolute(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("gob", func(t *testing.T) {
|
||||
if tc.gob == "\x00" && tc.sGob == "\x00" {
|
||||
// these values mark the current test to skip gob
|
||||
return
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
t.Run("encode", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// encode is unchecked
|
||||
if errors.Is(tc.wantErr, syscall.EINVAL) {
|
||||
return
|
||||
@@ -210,6 +235,8 @@ func TestCodecAbsolute(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("decode", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
{
|
||||
var gotA *Absolute
|
||||
err := gob.NewDecoder(strings.NewReader(tc.gob)).Decode(&gotA)
|
||||
@@ -244,7 +271,11 @@ func TestCodecAbsolute(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("json", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("marshal", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// marshal is unchecked
|
||||
if errors.Is(tc.wantErr, syscall.EINVAL) {
|
||||
return
|
||||
@@ -279,6 +310,8 @@ func TestCodecAbsolute(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("unmarshal", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
{
|
||||
var gotA *Absolute
|
||||
err := json.Unmarshal([]byte(tc.json), &gotA)
|
||||
@@ -314,6 +347,8 @@ func TestCodecAbsolute(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("json passthrough", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
wantErr := "invalid character ':' looking for beginning of value"
|
||||
if err := new(Absolute).UnmarshalJSON([]byte(":3")); err == nil || err.Error() != wantErr {
|
||||
t.Errorf("UnmarshalJSON: error = %v, want %s", err, wantErr)
|
||||
@@ -322,7 +357,11 @@ func TestCodecAbsolute(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAbsoluteWrap(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("join", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
want := "/etc/nix/nix.conf"
|
||||
if got := MustAbs("/etc").Append("nix", "nix.conf"); got.String() != want {
|
||||
t.Errorf("Append: %q, want %q", got, want)
|
||||
@@ -330,6 +369,8 @@ func TestAbsoluteWrap(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("dir", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
want := "/"
|
||||
if got := MustAbs("/etc").Dir(); got.String() != want {
|
||||
t.Errorf("Dir: %q, want %q", got, want)
|
||||
@@ -337,6 +378,8 @@ func TestAbsoluteWrap(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("sort", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
want := []*Absolute{MustAbs("/etc"), MustAbs("/proc"), MustAbs("/sys")}
|
||||
got := []*Absolute{MustAbs("/proc"), MustAbs("/sys"), MustAbs("/etc")}
|
||||
SortAbs(got)
|
||||
@@ -346,6 +389,8 @@ func TestAbsoluteWrap(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("compact", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
want := []*Absolute{MustAbs("/etc"), MustAbs("/proc"), MustAbs("/sys")}
|
||||
if got := CompactAbs([]*Absolute{MustAbs("/etc"), MustAbs("/proc"), MustAbs("/proc"), MustAbs("/sys")}); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("CompactAbs: %#v, want %#v", got, want)
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func TestEscapeOverlayDataSegment(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
s string
|
||||
@@ -19,6 +21,8 @@ func TestEscapeOverlayDataSegment(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if got := check.EscapeOverlayDataSegment(tc.s); got != tc.want {
|
||||
t.Errorf("escapeOverlayDataSegment: %s, want %s", got, tc.want)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import (
|
||||
)
|
||||
|
||||
func TestStartError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
err error
|
||||
@@ -137,6 +139,8 @@ func TestStartError(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("error", func(t *testing.T) {
|
||||
if got := tc.err.Error(); got != tc.s {
|
||||
t.Errorf("Error: %q, want %q", got, tc.s)
|
||||
@@ -352,6 +356,8 @@ var containerTestCases = []struct {
|
||||
}
|
||||
|
||||
func TestContainer(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("cancel", testContainerCancel(nil, func(t *testing.T, c *container.Container) {
|
||||
wantErr := context.Canceled
|
||||
wantExitCode := 0
|
||||
@@ -385,6 +391,8 @@ func TestContainer(t *testing.T) {
|
||||
|
||||
for i, tc := range containerTestCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
wantOps, wantOpsCtx := tc.ops(t)
|
||||
wantMnt := tc.mnt(t, wantOpsCtx)
|
||||
|
||||
@@ -504,6 +512,7 @@ func testContainerCancel(
|
||||
waitCheck func(t *testing.T, c *container.Container),
|
||||
) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := context.WithTimeout(t.Context(), helperDefaultTimeout)
|
||||
|
||||
c := helperNewContainer(ctx, "block")
|
||||
@@ -546,6 +555,7 @@ func testContainerCancel(
|
||||
}
|
||||
|
||||
func TestContainerString(t *testing.T) {
|
||||
t.Parallel()
|
||||
msg := message.NewMsg(nil)
|
||||
c := container.NewCommand(t.Context(), msg, check.MustAbs("/run/current-system/sw/bin/ldd"), "ldd", "/usr/bin/env")
|
||||
c.SeccompFlags |= seccomp.AllowMultiarch
|
||||
|
||||
@@ -32,10 +32,12 @@ func checkOpsValid(t *testing.T, testCases []opValidTestCase) {
|
||||
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
if got := tc.op.Valid(); got != tc.want {
|
||||
t.Errorf("Valid: %v, want %v", got, tc.want)
|
||||
@@ -56,10 +58,12 @@ func checkOpsBuilder(t *testing.T, testCases []opsBuilderTestCase) {
|
||||
|
||||
t.Run("build", func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
if !slices.EqualFunc(*tc.ops, tc.want, func(op Op, v Op) bool { return op.Is(v) }) {
|
||||
t.Errorf("Ops: %#v, want %#v", tc.ops, tc.want)
|
||||
@@ -80,10 +84,12 @@ func checkOpIs(t *testing.T, testCases []opIsTestCase) {
|
||||
|
||||
t.Run("is", func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
if got := tc.op.Is(tc.v); got != tc.want {
|
||||
t.Errorf("Is: %v, want %v", got, tc.want)
|
||||
@@ -106,10 +112,12 @@ func checkOpMeta(t *testing.T, testCases []opMetaTestCase) {
|
||||
|
||||
t.Run("meta", func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
t.Run("prefix", func(t *testing.T) {
|
||||
t.Helper()
|
||||
@@ -150,6 +158,7 @@ func checkSimple(t *testing.T, fname string, testCases []simpleTestCase) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
wait4signal := make(chan struct{})
|
||||
k := &kstub{wait4signal, stub.New(t, func(s *stub.Stub[syscallDispatcher]) syscallDispatcher { return &kstub{wait4signal, s} }, tc.want)}
|
||||
@@ -183,10 +192,12 @@ func checkOpBehaviour(t *testing.T, testCases []opBehaviourTestCase) {
|
||||
|
||||
t.Run("behaviour", func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Parallel()
|
||||
|
||||
k := &kstub{nil, stub.New(t,
|
||||
func(s *stub.Stub[syscallDispatcher]) syscallDispatcher { return &kstub{nil, s} },
|
||||
|
||||
@@ -14,6 +14,8 @@ import (
|
||||
)
|
||||
|
||||
func TestMessageFromError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
err error
|
||||
@@ -54,6 +56,7 @@ func TestMessageFromError(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got, ok := messageFromError(tc.err)
|
||||
if got != tc.want {
|
||||
t.Errorf("messageFromError: %q, want %q", got, tc.want)
|
||||
@@ -66,6 +69,8 @@ func TestMessageFromError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMountError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
err error
|
||||
@@ -111,6 +116,7 @@ func TestMountError(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("is", func(t *testing.T) {
|
||||
if !errors.Is(tc.err, tc.errno) {
|
||||
t.Errorf("Is: %#v is not %v", tc.err, tc.errno)
|
||||
@@ -125,6 +131,7 @@ func TestMountError(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("zero", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if errors.Is(new(MountError), syscall.Errno(0)) {
|
||||
t.Errorf("Is: zero MountError unexpected true")
|
||||
}
|
||||
@@ -132,6 +139,8 @@ func TestMountError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestErrnoFallback(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
err error
|
||||
@@ -154,6 +163,7 @@ func TestErrnoFallback(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
errno, err := errnoFallback(tc.name, Nonexistent, tc.err)
|
||||
if errno != tc.wantErrno {
|
||||
t.Errorf("errnoFallback: errno = %v, want %v", errno, tc.wantErrno)
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func TestExecutable(t *testing.T) {
|
||||
t.Parallel()
|
||||
for i := 0; i < 16; i++ {
|
||||
if got := container.MustExecutable(message.NewMsg(nil)); got != os.Args[0] {
|
||||
t.Errorf("MustExecutable: %q, want %q",
|
||||
got, os.Args[0])
|
||||
t.Errorf("MustExecutable: %q, want %q", got, os.Args[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestInitEntrypoint(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkSimple(t, "initEntrypoint", []simpleTestCase{
|
||||
{"getpid", func(k *kstub) error { initEntrypoint(k, k); return nil }, stub.Expect{
|
||||
@@ -2649,6 +2650,7 @@ func TestInitEntrypoint(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOpsGrow(t *testing.T) {
|
||||
t.Parallel()
|
||||
ops := new(Ops)
|
||||
ops.Grow(1 << 4)
|
||||
if got := cap(*ops); got == 0 {
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestBindMountOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkOpBehaviour(t, []opBehaviourTestCase{
|
||||
{"ENOENT not optional", new(Params), &BindMountOp{
|
||||
Source: check.MustAbs("/bin/"),
|
||||
@@ -164,7 +166,10 @@ func TestBindMountOp(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("unreachable", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("nil sourceFinal not optional", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
wantErr := OpStateError("bind")
|
||||
if err := new(BindMountOp).apply(nil, nil); !errors.Is(err, wantErr) {
|
||||
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func TestMountDevOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkOpBehaviour(t, []opBehaviourTestCase{
|
||||
{"mountTmpfs", &Params{ParentPerm: 0750, RetainSession: true}, &MountDevOp{
|
||||
Target: check.MustAbs("/dev/"),
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func TestMkdirOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkOpBehaviour(t, []opBehaviourTestCase{
|
||||
{"success", new(Params), &MkdirOp{
|
||||
Path: check.MustAbs("/.hakurei"),
|
||||
|
||||
@@ -10,7 +10,11 @@ import (
|
||||
)
|
||||
|
||||
func TestMountOverlayOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("argument error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
err *OverlayArgumentError
|
||||
@@ -30,6 +34,7 @@ func TestMountOverlayOp(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := tc.err.Error(); got != tc.want {
|
||||
t.Errorf("Error: %q, want %q", got, tc.want)
|
||||
}
|
||||
@@ -270,7 +275,10 @@ func TestMountOverlayOp(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("unreachable", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("nil Upper non-nil Work not ephemeral", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
wantErr := OpStateError("overlay")
|
||||
if err := (&MountOverlayOp{
|
||||
Work: check.MustAbs("/"),
|
||||
|
||||
@@ -14,6 +14,7 @@ func TestTmpfileOp(t *testing.T) {
|
||||
samplePath = check.MustAbs("/etc/passwd")
|
||||
sampleData = []byte(sampleDataString)
|
||||
)
|
||||
t.Parallel()
|
||||
|
||||
checkOpBehaviour(t, []opBehaviourTestCase{
|
||||
{"createTemp", &Params{ParentPerm: 0700}, &TmpfileOp{
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func TestMountProcOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkOpBehaviour(t, []opBehaviourTestCase{
|
||||
{"mkdir", &Params{ParentPerm: 0755},
|
||||
&MountProcOp{
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func TestRemountOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkOpBehaviour(t, []opBehaviourTestCase{
|
||||
{"success", new(Params), &RemountOp{
|
||||
Target: check.MustAbs("/"),
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func TestSymlinkOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkOpBehaviour(t, []opBehaviourTestCase{
|
||||
{"mkdir", &Params{ParentPerm: 0700}, &SymlinkOp{
|
||||
Target: check.MustAbs("/etc/nixos"),
|
||||
|
||||
@@ -10,7 +10,10 @@ import (
|
||||
)
|
||||
|
||||
func TestMountTmpfsOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("size error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tmpfsSizeError := TmpfsSizeError(-1)
|
||||
want := "tmpfs size -1 out of bounds"
|
||||
if got := tmpfsSizeError.Error(); got != want {
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestLandlockString(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
rulesetAttr *container.RulesetAttr
|
||||
@@ -46,6 +48,7 @@ func TestLandlockString(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := tc.rulesetAttr.String(); got != tc.want {
|
||||
t.Errorf("String: %s, want %s", got, tc.want)
|
||||
}
|
||||
@@ -54,6 +57,7 @@ func TestLandlockString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLandlockAttrSize(t *testing.T) {
|
||||
t.Parallel()
|
||||
want := 24
|
||||
if got := unsafe.Sizeof(container.RulesetAttr{}); got != uintptr(want) {
|
||||
t.Errorf("Sizeof: %d, want %d", got, want)
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func TestBindMount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkSimple(t, "bindMount", []simpleTestCase{
|
||||
{"mount", func(k *kstub) error {
|
||||
return newProcPaths(k, hostPath).bindMount(nil, "/host/nix", "/sysroot/nix", syscall.MS_RDONLY)
|
||||
@@ -34,6 +36,8 @@ func TestBindMount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const sampleMountinfoNix = `254 407 253:0 / /host rw,relatime master:1 - ext4 /dev/disk/by-label/nixos rw
|
||||
255 254 0:28 / /host/mnt/.ro-cwd ro,noatime master:2 - 9p cwd ro,access=client,msize=16384,trans=virtio
|
||||
256 254 0:29 / /host/nix/.ro-store rw,relatime master:3 - 9p nix-store rw,cache=f,access=client,msize=16384,trans=virtio
|
||||
@@ -216,6 +220,8 @@ func TestRemount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemountWithFlags(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkSimple(t, "remountWithFlags", []simpleTestCase{
|
||||
{"noop unmatched", func(k *kstub) error {
|
||||
return remountWithFlags(k, k, &vfs.MountInfoNode{MountInfoEntry: &vfs.MountInfoEntry{VfsOptstr: "rw,relatime,cat"}}, 0)
|
||||
@@ -236,6 +242,8 @@ func TestRemountWithFlags(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMountTmpfs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkSimple(t, "mountTmpfs", []simpleTestCase{
|
||||
{"mkdirAll", func(k *kstub) error {
|
||||
return mountTmpfs(k, "ephemeral", "/sysroot/run/user/1000", 0, 1<<10, 0700)
|
||||
@@ -260,6 +268,8 @@ func TestMountTmpfs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParentPerm(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
perm os.FileMode
|
||||
want os.FileMode
|
||||
@@ -275,6 +285,7 @@ func TestParentPerm(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.perm.String(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := parentPerm(tc.perm); got != tc.want {
|
||||
t.Errorf("parentPerm: %#o, want %#o", got, tc.want)
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func Export(fd int, rules []NativeRule, flags ExportFlag) error {
|
||||
|
||||
var ret C.int
|
||||
|
||||
rulesPinner := new(runtime.Pinner)
|
||||
var rulesPinner runtime.Pinner
|
||||
for i := range rules {
|
||||
rule := &rules[i]
|
||||
rulesPinner.Pin(rule)
|
||||
@@ -189,6 +189,5 @@ func syscallResolveName(s string) (trap int) {
|
||||
v := C.CString(s)
|
||||
trap = int(C.seccomp_syscall_resolve_name(v))
|
||||
C.free(unsafe.Pointer(v))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
)
|
||||
|
||||
func TestExport(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
flags ExportFlag
|
||||
@@ -32,14 +34,15 @@ func TestExport(t *testing.T) {
|
||||
{"hakurei tty", 0, PresetExt | PresetDenyNS | PresetDenyDevel, false},
|
||||
}
|
||||
|
||||
buf := make([]byte, 8)
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
e := New(Preset(tc.presets, tc.flags), tc.flags)
|
||||
want := bpfExpected[bpfPreset{tc.flags, tc.presets}]
|
||||
digest := sha512.New()
|
||||
|
||||
if _, err := io.CopyBuffer(digest, e, buf); (err != nil) != tc.wantErr {
|
||||
if _, err := io.Copy(digest, e); (err != nil) != tc.wantErr {
|
||||
t.Errorf("Exporter: error = %v, wantErr %v", err, tc.wantErr)
|
||||
return
|
||||
}
|
||||
@@ -47,7 +50,7 @@ func TestExport(t *testing.T) {
|
||||
t.Errorf("Close: error = %v", err)
|
||||
}
|
||||
if got := digest.Sum(nil); !slices.Equal(got, want) {
|
||||
t.Fatalf("Export() hash = %x, want %x",
|
||||
t.Fatalf("Export: hash = %x, want %x",
|
||||
got, want)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ Methods of Encoder are not safe for concurrent use.
|
||||
|
||||
An Encoder must not be copied after first use.
|
||||
*/
|
||||
type Encoder struct {
|
||||
*exporter
|
||||
}
|
||||
type Encoder struct{ *exporter }
|
||||
|
||||
func (e *Encoder) Read(p []byte) (n int, err error) {
|
||||
if err = e.prepare(); err != nil {
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func TestLibraryError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
sample *seccomp.LibraryError
|
||||
@@ -41,6 +43,8 @@ func TestLibraryError(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if errors.Is(tc.sample, tc.compare) != tc.wantIs {
|
||||
t.Errorf("errors.Is(%#v, %#v) did not return %v",
|
||||
tc.sample, tc.compare, tc.wantIs)
|
||||
@@ -54,6 +58,8 @@ func TestLibraryError(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("invalid", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
wantPanic := "invalid libseccomp error"
|
||||
defer func() {
|
||||
if r := recover(); r != wantPanic {
|
||||
|
||||
@@ -5,15 +5,17 @@ import (
|
||||
)
|
||||
|
||||
func TestSyscallResolveName(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for name, want := range Syscalls() {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if got := syscallResolveName(name); got != want {
|
||||
t.Errorf("syscallResolveName(%q) = %d, want %d",
|
||||
name, got, want)
|
||||
t.Errorf("syscallResolveName(%q) = %d, want %d", name, got, want)
|
||||
}
|
||||
if got, ok := SyscallResolveName(name); !ok || got != want {
|
||||
t.Errorf("SyscallResolveName(%q) = %d, want %d",
|
||||
name, got, want)
|
||||
t.Errorf("SyscallResolveName(%q) = %d, want %d", name, got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,13 +8,17 @@ import (
|
||||
)
|
||||
|
||||
func TestCallError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("contains false", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if err := new(stub.Call).Error(true, false, true); !reflect.DeepEqual(err, stub.ErrCheck) {
|
||||
t.Errorf("Error: %#v, want %#v", err, stub.ErrCheck)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("passthrough", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
wantErr := stub.UniqueError(0xbabe)
|
||||
if err := (&stub.Call{Err: wantErr}).Error(true); !reflect.DeepEqual(err, wantErr) {
|
||||
t.Errorf("Error: %#v, want %#v", err, wantErr)
|
||||
|
||||
@@ -9,7 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func TestUniqueError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("format", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
want := "unique error 2989 injected by the test suite"
|
||||
if got := stub.UniqueError(0xbad).Error(); got != want {
|
||||
t.Errorf("Error: %q, want %q", got, want)
|
||||
@@ -17,13 +20,17 @@ func TestUniqueError(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("is", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("type", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if errors.Is(stub.UniqueError(0), syscall.ENOTRECOVERABLE) {
|
||||
t.Error("Is: unexpected true")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("val", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if errors.Is(stub.UniqueError(0), stub.UniqueError(1)) {
|
||||
t.Error("Is: unexpected true")
|
||||
}
|
||||
|
||||
@@ -32,13 +32,20 @@ func (o *overrideTFailNow) Fail() {
|
||||
}
|
||||
|
||||
func TestHandleExit(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("exit", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer stub.HandleExit(t)
|
||||
panic(stub.PanicExit)
|
||||
})
|
||||
|
||||
t.Run("goexit", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("FailNow", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ot := &overrideTFailNow{T: t}
|
||||
defer func() {
|
||||
if !ot.failNow {
|
||||
@@ -50,6 +57,8 @@ func TestHandleExit(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Fail", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ot := &overrideTFailNow{T: t}
|
||||
defer func() {
|
||||
if !ot.fail {
|
||||
@@ -62,11 +71,16 @@ func TestHandleExit(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer stub.HandleExit(t)
|
||||
})
|
||||
|
||||
t.Run("passthrough", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("toplevel", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
want := 0xcafebabe
|
||||
if r := recover(); r != want {
|
||||
@@ -79,6 +93,8 @@ func TestHandleExit(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("new", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
want := 0xcafe
|
||||
if r := recover(); r != want {
|
||||
|
||||
@@ -36,8 +36,14 @@ func (t *overrideT) Errorf(format string, args ...any) {
|
||||
}
|
||||
|
||||
func TestStub(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("goexit", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("FailNow", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != panicFailNow {
|
||||
t.Errorf("recover: %v", r)
|
||||
@@ -47,6 +53,8 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("SkipNow", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
want := "invalid call to SkipNow"
|
||||
if r := recover(); r != want {
|
||||
@@ -57,6 +65,8 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Skip", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
want := "invalid call to Skip"
|
||||
if r := recover(); r != want {
|
||||
@@ -67,6 +77,8 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Skipf", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
want := "invalid call to Skipf"
|
||||
if r := recover(); r != want {
|
||||
@@ -78,7 +90,11 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("new", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("success", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := New(t, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
||||
{"New", ExpectArgs{}, nil, nil},
|
||||
}, Tracks: []Expect{{Calls: []Call{
|
||||
@@ -112,6 +128,8 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("overrun", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ot := &overrideT{T: t}
|
||||
ot.error.Store(checkError(t, "New: track overrun"))
|
||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
||||
@@ -135,7 +153,11 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("expects", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("overrun", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ot := &overrideT{T: t}
|
||||
ot.error.Store(checkError(t, "Expects: advancing beyond expected calls"))
|
||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{})
|
||||
@@ -143,7 +165,11 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("separator", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("overrun", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ot := &overrideT{T: t}
|
||||
ot.errorf.Store(checkErrorf(t, "Expects: func = %s, separator overrun", "meow"))
|
||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
||||
@@ -153,6 +179,8 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("mismatch", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ot := &overrideT{T: t}
|
||||
ot.errorf.Store(checkErrorf(t, "Expects: separator, want %s", "panic"))
|
||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
||||
@@ -163,6 +191,8 @@ func TestStub(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("mismatch", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ot := &overrideT{T: t}
|
||||
ot.errorf.Store(checkErrorf(t, "Expects: func = %s, want %s", "meow", "nya"))
|
||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
||||
@@ -176,6 +206,8 @@ func TestStub(t *testing.T) {
|
||||
|
||||
func TestCheckArg(t *testing.T) {
|
||||
t.Run("oob negative", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
want := "invalid call to CheckArg"
|
||||
if r := recover(); r != want {
|
||||
@@ -191,12 +223,14 @@ func TestCheckArg(t *testing.T) {
|
||||
{"panic", ExpectArgs{PanicExit}, nil, nil},
|
||||
{"meow", ExpectArgs{-1}, nil, nil},
|
||||
}})
|
||||
|
||||
t.Run("match", func(t *testing.T) {
|
||||
s.Expects("panic")
|
||||
if !CheckArg(s, "v", PanicExit, 0) {
|
||||
t.Errorf("CheckArg: unexpected false")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("mismatch", func(t *testing.T) {
|
||||
defer HandleExit(t)
|
||||
s.Expects("meow")
|
||||
@@ -205,6 +239,7 @@ func TestCheckArg(t *testing.T) {
|
||||
t.Errorf("CheckArg: unexpected true")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("oob", func(t *testing.T) {
|
||||
s.pos++
|
||||
defer func() {
|
||||
@@ -218,7 +253,11 @@ func TestCheckArg(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckArgReflect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("oob lower", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
want := "invalid call to CheckArgReflect"
|
||||
if r := recover(); r != want {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func TestUnmangle(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
want string
|
||||
sample string
|
||||
@@ -17,6 +19,7 @@ func TestUnmangle(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.want, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := vfs.Unmangle(tc.sample)
|
||||
if got != tc.want {
|
||||
t.Errorf("Unmangle: %q, want %q",
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
)
|
||||
|
||||
func TestDecoderError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
err *vfs.DecoderError
|
||||
@@ -35,13 +37,17 @@ func TestDecoderError(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := tc.err.Error(); got != tc.want {
|
||||
t.Errorf("Error: %s, want %s", got, tc.want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("is", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !errors.Is(tc.err, tc.target) {
|
||||
t.Errorf("Is: unexpected false")
|
||||
}
|
||||
@@ -54,6 +60,8 @@ func TestDecoderError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []mountInfoTest{
|
||||
{"count", sampleMountinfoBase + `
|
||||
21 20 0:53/ /mnt/test rw,relatime - tmpfs rw
|
||||
@@ -187,7 +195,10 @@ id 20 0:53 / /mnt/test rw,relatime shared:212 - tmpfs rw
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("decode", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
var got *vfs.MountInfo
|
||||
d := vfs.NewMountInfoDecoder(strings.NewReader(tc.sample))
|
||||
err := d.Decode(&got)
|
||||
@@ -206,6 +217,7 @@ id 20 0:53 / /mnt/test rw,relatime shared:212 - tmpfs rw
|
||||
})
|
||||
|
||||
t.Run("iter", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
d := vfs.NewMountInfoDecoder(strings.NewReader(tc.sample))
|
||||
tc.check(t, d, "Entries",
|
||||
d.Entries(), d.Err)
|
||||
@@ -217,6 +229,7 @@ id 20 0:53 / /mnt/test rw,relatime shared:212 - tmpfs rw
|
||||
})
|
||||
|
||||
t.Run("yield", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
d := vfs.NewMountInfoDecoder(strings.NewReader(tc.sample))
|
||||
v := false
|
||||
d.Entries()(func(entry *vfs.MountInfoEntry) bool { v = !v; return v })
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func TestUnfold(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
sample string
|
||||
@@ -50,6 +52,8 @@ func TestUnfold(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
d := vfs.NewMountInfoDecoder(strings.NewReader(tc.sample))
|
||||
got, err := d.Unfold(tc.target)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user