aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/output_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-31 13:51:21 +0900
committerOphestra <cat@gensokyo.uk>2025-08-31 13:51:21 +0900
commitb489a3bba15bc6d808d7cc9c17f74dd833d32b9e (patch)
tree4cf9ccf921a1e8fbb8e3d83da74631d35ca1034e /system/output_test.go
parent780e3e546581dd4a46b887310a665eea06f3279a (diff)
system/output: implement MessageError
This error is also formatted differently based on state. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/output_test.go')
-rw-r--r--system/output_test.go56
1 files changed, 50 insertions, 6 deletions
diff --git a/system/output_test.go b/system/output_test.go
index ba760e84..9ad949c3 100644
--- a/system/output_test.go
+++ b/system/output_test.go
@@ -19,27 +19,33 @@ func TestOpError(t *testing.T) {
s string
is error
isF error
+ msg string
}{
{"message", newOpErrorMessage("dbus", ErrDBusConfig,
"attempted to create message bus proxy args without session bus config", false),
"attempted to create message bus proxy args without session bus config",
- ErrDBusConfig, syscall.ENOTRECOVERABLE},
+ ErrDBusConfig, syscall.ENOTRECOVERABLE,
+ "attempted to create message bus proxy args without session bus config"},
{"apply", newOpError("tmpfile", syscall.EBADE, false),
"apply tmpfile: invalid exchange",
- syscall.EBADE, syscall.EBADF},
+ syscall.EBADE, syscall.EBADF,
+ "cannot apply tmpfile: invalid exchange"},
{"revert", newOpError("wayland", syscall.EBADF, true),
"revert wayland: bad file descriptor",
- syscall.EBADF, syscall.EBADE},
+ syscall.EBADF, syscall.EBADE,
+ "cannot revert wayland: bad file descriptor"},
{"path", newOpError("tmpfile", &os.PathError{Op: "stat", Path: "/run/dbus", Err: syscall.EISDIR}, false),
"stat /run/dbus: is a directory",
- syscall.EISDIR, syscall.ENOTDIR},
+ syscall.EISDIR, syscall.ENOTDIR,
+ "cannot stat /run/dbus: is a directory"},
{"net", newOpError("wayland", &net.OpError{Op: "dial", Net: "unix", Addr: &net.UnixAddr{Name: "/run/user/1000/wayland-1", Net: "unix"}, Err: syscall.ENOENT}, false),
"dial unix /run/user/1000/wayland-1: no such file or directory",
- syscall.ENOENT, syscall.EPERM},
+ syscall.ENOENT, syscall.EPERM,
+ "cannot dial unix /run/user/1000/wayland-1: no such file or directory"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
@@ -48,6 +54,7 @@ func TestOpError(t *testing.T) {
t.Errorf("Error: %q, want %q", got, tc.s)
}
})
+
t.Run("is", func(t *testing.T) {
if !errors.Is(tc.err, tc.is) {
t.Error("Is: unexpected false")
@@ -56,6 +63,17 @@ func TestOpError(t *testing.T) {
t.Error("Is: unexpected true")
}
})
+
+ t.Run("msg", func(t *testing.T) {
+ if got, ok := container.GetErrorMessage(tc.err); !ok {
+ if tc.msg != "" {
+ t.Errorf("GetErrorMessage: err does not implement MessageError")
+ }
+ return
+ } else if got != tc.msg {
+ t.Errorf("GetErrorMessage: %q, want %q", got, tc.msg)
+ }
+ })
})
}
@@ -103,14 +121,40 @@ func TestPrintJoinedError(t *testing.T) {
want [][]any
}{
{"nil", nil, [][]any{{"not a joined error:", nil}}},
- {"unwrapped", syscall.EINVAL, [][]any{{"not a joined error:", syscall.EINVAL}}},
{"single", errors.Join(syscall.EINVAL), [][]any{{"invalid argument"}}},
+ {"unwrapped", syscall.EINVAL, [][]any{{"not a joined error:", syscall.EINVAL}}},
+ {"unwrapped message", &OpError{
+ Op: "meow",
+ Err: syscall.EBADFD,
+ }, [][]any{
+ {"cannot apply meow: file descriptor in bad state"},
+ }},
+
{"many", errors.Join(syscall.ENOTRECOVERABLE, syscall.ETIMEDOUT, syscall.EBADFD), [][]any{
{"state not recoverable"},
{"connection timed out"},
{"file descriptor in bad state"},
}},
+ {"many message", errors.Join(
+ &container.StartError{
+ Step: "meow",
+ Err: syscall.ENOMEM,
+ },
+ &os.PathError{
+ Op: "meow",
+ Path: "/proc/nonexistent",
+ Err: syscall.ENOSYS,
+ },
+ &OpError{
+ Op: "meow",
+ Err: syscall.ENODEV,
+ Revert: true,
+ }), [][]any{
+ {"cannot meow: cannot allocate memory"},
+ {"meow /proc/nonexistent: function not implemented"},
+ {"cannot revert meow: no such device"},
+ }},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {