diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-13 04:38:48 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-13 04:38:48 +0900 |
| commit | 7638a44fa613f23434318bdf136723aa010e8638 (patch) | |
| tree | 7b5270ed4e9b6d7f1ee0f28c58d8077aa1d18005 /container | |
| parent | a14b6535a66cb7ac0fc4827f767ffaee0ce04b57 (diff) | |
treewide: parallel tests
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>
Diffstat (limited to 'container')
33 files changed, 252 insertions, 20 deletions
diff --git a/container/autoetc_test.go b/container/autoetc_test.go index 30f46e50..a7e3ae49 100644 --- a/container/autoetc_test.go +++ b/container/autoetc_test.go @@ -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" diff --git a/container/autoroot_test.go b/container/autoroot_test.go index d53edc71..129ff4ed 100644 --- a/container/autoroot_test.go +++ b/container/autoroot_test.go @@ -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{ diff --git a/container/capability_test.go b/container/capability_test.go index 21043fb0..9494480a 100644 --- a/container/capability_test.go +++ b/container/capability_test.go @@ -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) } diff --git a/container/check/absolute_test.go b/container/check/absolute_test.go index a25c0ada..2746ec79 100644 --- a/container/check/absolute_test.go +++ b/container/check/absolute_test.go @@ -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) diff --git a/container/check/overlay_test.go b/container/check/overlay_test.go index bd90236d..8fdcd69f 100644 --- a/container/check/overlay_test.go +++ b/container/check/overlay_test.go @@ -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) } diff --git a/container/container_test.go b/container/container_test.go index bc90d8ff..e692ab3c 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -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 diff --git a/container/dispatcher_test.go b/container/dispatcher_test.go index 4e6ee76f..3e5cb91f 100644 --- a/container/dispatcher_test.go +++ b/container/dispatcher_test.go @@ -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} }, diff --git a/container/errors_test.go b/container/errors_test.go index c2d3fa7a..bf742651 100644 --- a/container/errors_test.go +++ b/container/errors_test.go @@ -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) diff --git a/container/executable_test.go b/container/executable_test.go index 33981bb6..38e89437 100644 --- a/container/executable_test.go +++ b/container/executable_test.go @@ -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]) } } } diff --git a/container/init_test.go b/container/init_test.go index 1db81741..49739726 100644 --- a/container/init_test.go +++ b/container/init_test.go @@ -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 { diff --git a/container/initbind_test.go b/container/initbind_test.go index 41a1d972..323a0328 100644 --- a/container/initbind_test.go +++ b/container/initbind_test.go @@ -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) diff --git a/container/initdev_test.go b/container/initdev_test.go index 4081dd29..e885c359 100644 --- a/container/initdev_test.go +++ b/container/initdev_test.go @@ -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/"), diff --git a/container/initmkdir_test.go b/container/initmkdir_test.go index 31f3fb86..4bec4fa4 100644 --- a/container/initmkdir_test.go +++ b/container/initmkdir_test.go @@ -9,6 +9,8 @@ import ( ) func TestMkdirOp(t *testing.T) { + t.Parallel() + checkOpBehaviour(t, []opBehaviourTestCase{ {"success", new(Params), &MkdirOp{ Path: check.MustAbs("/.hakurei"), diff --git a/container/initoverlay_test.go b/container/initoverlay_test.go index ad07ef97..1c0e642a 100644 --- a/container/initoverlay_test.go +++ b/container/initoverlay_test.go @@ -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("/"), diff --git a/container/initplace_test.go b/container/initplace_test.go index 03f298b6..afeddbe5 100644 --- a/container/initplace_test.go +++ b/container/initplace_test.go @@ -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{ diff --git a/container/initproc_test.go b/container/initproc_test.go index 86334143..12b4def7 100644 --- a/container/initproc_test.go +++ b/container/initproc_test.go @@ -9,6 +9,8 @@ import ( ) func TestMountProcOp(t *testing.T) { + t.Parallel() + checkOpBehaviour(t, []opBehaviourTestCase{ {"mkdir", &Params{ParentPerm: 0755}, &MountProcOp{ diff --git a/container/initremount_test.go b/container/initremount_test.go index 74afe0b4..03a7b645 100644 --- a/container/initremount_test.go +++ b/container/initremount_test.go @@ -9,6 +9,8 @@ import ( ) func TestRemountOp(t *testing.T) { + t.Parallel() + checkOpBehaviour(t, []opBehaviourTestCase{ {"success", new(Params), &RemountOp{ Target: check.MustAbs("/"), diff --git a/container/initsymlink_test.go b/container/initsymlink_test.go index 1b69740a..e260b518 100644 --- a/container/initsymlink_test.go +++ b/container/initsymlink_test.go @@ -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"), diff --git a/container/inittmpfs_test.go b/container/inittmpfs_test.go index f67c45cb..f5dfafad 100644 --- a/container/inittmpfs_test.go +++ b/container/inittmpfs_test.go @@ -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 { diff --git a/container/landlock_test.go b/container/landlock_test.go index d204bc31..87dc2496 100644 --- a/container/landlock_test.go +++ b/container/landlock_test.go @@ -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) diff --git a/container/mount_test.go b/container/mount_test.go index daa2287a..c6a5710f 100644 --- a/container/mount_test.go +++ b/container/mount_test.go @@ -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) } diff --git a/container/seccomp/libseccomp.go b/container/seccomp/libseccomp.go index c7a3b670..21236a06 100644 --- a/container/seccomp/libseccomp.go +++ b/container/seccomp/libseccomp.go @@ -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 } diff --git a/container/seccomp/libseccomp_test.go b/container/seccomp/libseccomp_test.go index 81f52511..d947105c 100644 --- a/container/seccomp/libseccomp_test.go +++ b/container/seccomp/libseccomp_test.go @@ -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 } diff --git a/container/seccomp/proc.go b/container/seccomp/proc.go index 7027cc6b..fb6f5430 100644 --- a/container/seccomp/proc.go +++ b/container/seccomp/proc.go @@ -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 { diff --git a/container/seccomp/seccomp_test.go b/container/seccomp/seccomp_test.go index a3dcad56..c19f2c49 100644 --- a/container/seccomp/seccomp_test.go +++ b/container/seccomp/seccomp_test.go @@ -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 { diff --git a/container/seccomp/syscall_test.go b/container/seccomp/syscall_test.go index 933f060b..e385a12c 100644 --- a/container/seccomp/syscall_test.go +++ b/container/seccomp/syscall_test.go @@ -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) } }) } diff --git a/container/stub/call_test.go b/container/stub/call_test.go index 67187987..db0b59dc 100644 --- a/container/stub/call_test.go +++ b/container/stub/call_test.go @@ -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) diff --git a/container/stub/errors_test.go b/container/stub/errors_test.go index 4d9252de..604841ac 100644 --- a/container/stub/errors_test.go +++ b/container/stub/errors_test.go @@ -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") } diff --git a/container/stub/exit_test.go b/container/stub/exit_test.go index 4e935ff4..15ad31f1 100644 --- a/container/stub/exit_test.go +++ b/container/stub/exit_test.go @@ -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 { diff --git a/container/stub/stub_test.go b/container/stub/stub_test.go index de9971f3..9c9b0eb8 100644 --- a/container/stub/stub_test.go +++ b/container/stub/stub_test.go @@ -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 { diff --git a/container/vfs/mangle_test.go b/container/vfs/mangle_test.go index 2cc65be0..0227e8e1 100644 --- a/container/vfs/mangle_test.go +++ b/container/vfs/mangle_test.go @@ -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", diff --git a/container/vfs/mountinfo_test.go b/container/vfs/mountinfo_test.go index 7d9b2406..ecca370a 100644 --- a/container/vfs/mountinfo_test.go +++ b/container/vfs/mountinfo_test.go @@ -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 }) diff --git a/container/vfs/unfold_test.go b/container/vfs/unfold_test.go index e04c51a5..3e9d2702 100644 --- a/container/vfs/unfold_test.go +++ b/container/vfs/unfold_test.go @@ -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) |
