diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-29 01:37:13 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-29 01:37:13 +0900 |
| commit | f24dd4ab8c3f1440654f9c5c18e50f03fdf85e27 (patch) | |
| tree | c59d04453fa1859f6f1c4fec2110f53fcea339dc /container/errors_test.go | |
| parent | a462341a0a3e1132f3fcdb1efb0f7a56e851a9e1 (diff) | |
container/init: handle unwrapped errors
This is much cleaner from both the return statement and the error handling.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/errors_test.go')
| -rw-r--r-- | container/errors_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/container/errors_test.go b/container/errors_test.go index 3d327430..eae5ee7d 100644 --- a/container/errors_test.go +++ b/container/errors_test.go @@ -8,6 +8,52 @@ import ( "testing" ) +func TestMessageFromError(t *testing.T) { + testCases := []struct { + name string + err error + want string + wantOk bool + }{ + {"mount", &MountError{ + Source: SourceTmpfsEphemeral, + Target: "/sysroot/tmp", + Fstype: FstypeTmpfs, + Flags: syscall.MS_NOSUID | syscall.MS_NODEV, + Data: zeroString, + Errno: syscall.EINVAL, + }, "cannot mount tmpfs on /sysroot/tmp: invalid argument", true}, + + {"path", &os.PathError{ + Op: "mount", + Path: "/sysroot", + Err: errUnique, + }, "cannot mount /sysroot: unique error injected by the test suite", true}, + + {"absolute", &AbsoluteError{"etc/mtab"}, + `path "etc/mtab" is not absolute`, true}, + + {"repeat", OpRepeatError("autoetc"), + "autoetc is not repeatable", true}, + + {"state", OpStateError("overlay"), + "impossible overlay state reached", true}, + + {"unsupported", errUnique, zeroString, false}, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + got, ok := messageFromError(tc.err) + if got != tc.want { + t.Errorf("messageFromError: %q, want %q", got, tc.want) + } + if ok != tc.wantOk { + t.Errorf("messageFromError: ok = %v, want %v", ok, tc.wantOk) + } + }) + } +} + func TestMountError(t *testing.T) { testCases := []struct { name string |
