aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/initdaemon_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-12-08 22:58:42 +0900
committerOphestra <cat@gensokyo.uk>2025-12-08 22:58:42 +0900
commite9fb1d7be540794ebe5027a08fbf97df189c6787 (patch)
tree6447dcdd7165fb2cb61dd1b46e47238d93bb54a7 /container/initdaemon_test.go
parentdafe9f8efc46bbd0fb391d1f7a93f05ee9751250 (diff)
container/initdaemon: copy wstatus from wait4 loop
Due to the special nature of the init process, direct use of wait outside the wait4 loop is racy. This change copies the wstatus from wait4 loop state instead. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/initdaemon_test.go')
-rw-r--r--container/initdaemon_test.go33
1 files changed, 29 insertions, 4 deletions
diff --git a/container/initdaemon_test.go b/container/initdaemon_test.go
index 5ab834db..ad8c7a93 100644
--- a/container/initdaemon_test.go
+++ b/container/initdaemon_test.go
@@ -6,8 +6,36 @@ import (
"hakurei.app/container/check"
"hakurei.app/container/stub"
+ "hakurei.app/message"
)
+func TestEarlyTerminationError(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ name string
+ err error
+ want string
+ msg string
+ }{
+ {"exited", &earlyTerminationError{
+ `daemon providing "/run/user/1971/pulse/native"`, 127 << 8,
+ }, "exit status 127", `daemon providing "/run/user/1971/pulse/native" exit status 127`},
+ }
+ 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)
+ }
+ if got := tc.err.(message.Error).Message(); got != tc.msg {
+ t.Errorf("Message: %s, want %s", got, tc.msg)
+ }
+ })
+ }
+}
+
func TestDaemonOp(t *testing.T) {
t.Parallel()
@@ -23,15 +51,12 @@ func TestDaemonOp(t *testing.T) {
call("isVerbose", stub.ExpectArgs{}, true, nil),
call("verbosef", stub.ExpectArgs{"starting %s", []any{`daemon providing "/run/user/1971/pulse/native"`}}, nil, nil),
call("start", stub.ExpectArgs{"/run/current-system/sw/bin/pipewire-pulse", []string{"/run/current-system/sw/bin/pipewire-pulse", "-v"}, []string{"\x00"}, "/"}, &os.Process{Pid: 0xcafe}, nil),
- call("New", stub.ExpectArgs{}, nil, nil),
call("stat", stub.ExpectArgs{"/run/user/1971/pulse/native"}, isDirFi(false), os.ErrNotExist),
call("stat", stub.ExpectArgs{"/run/user/1971/pulse/native"}, isDirFi(false), os.ErrNotExist),
call("stat", stub.ExpectArgs{"/run/user/1971/pulse/native"}, isDirFi(false), os.ErrNotExist),
call("stat", stub.ExpectArgs{"/run/user/1971/pulse/native"}, isDirFi(false), nil),
call("verbosef", stub.ExpectArgs{"daemon process %d ready", []any{0xcafe}}, nil, nil),
- }, Tracks: []stub.Expect{{Calls: []stub.Call{
- call("wait", stub.ExpectArgs{"/run/current-system/sw/bin/pipewire-pulse", []string{"/run/current-system/sw/bin/pipewire-pulse", "-v"}, []string{"\x00"}, "/"}, uintptr(stub.PanicExit), nil),
- }}}}, nil},
+ }}, nil},
})
checkOpsValid(t, []opValidTestCase{