aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/msg_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-21 21:59:07 +0900
committerOphestra <cat@gensokyo.uk>2025-08-22 19:27:31 +0900
commit09d284498109b847da0da1e2c5f883268a7f2d46 (patch)
tree3784dee4b4e4ec97a95cb222c70d05463ae640ef /container/msg_test.go
parentd500d6e55917e12a3f98b39cf0d29b6c96de9667 (diff)
container/init: wrap syscall helper functions
This allows tests to stub all kernel behaviour, enabling measurement of all function call arguments and error injection. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/msg_test.go')
-rw-r--r--container/msg_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/container/msg_test.go b/container/msg_test.go
index 6945c892..2ad42493 100644
--- a/container/msg_test.go
+++ b/container/msg_test.go
@@ -1,6 +1,7 @@
package container_test
import (
+ "errors"
"log"
"strings"
"sync/atomic"
@@ -12,6 +13,9 @@ import (
)
func TestDefaultMsg(t *testing.T) {
+ // bypass WrapErr testing behaviour
+ t.Setenv("GOPATH", container.Nonexistent)
+
{
w := log.Writer()
f := log.Flags()
@@ -79,6 +83,25 @@ func TestDefaultMsg(t *testing.T) {
// the function is a noop
t.Run("beforeExit", func(t *testing.T) { msg.BeforeExit() })
+
+ t.Run("checkedWrappedErr", func(t *testing.T) {
+ // temporarily re-enable testing behaviour
+ t.Setenv("GOPATH", "")
+ wrappedErr := msg.WrapErr(syscall.ENOTRECOVERABLE, "cannot cuddle cat:", syscall.ENOTRECOVERABLE)
+
+ t.Run("string", func(t *testing.T) {
+ want := "state not recoverable, a = [cannot cuddle cat: state not recoverable]"
+ if got := wrappedErr.Error(); got != want {
+ t.Errorf("Error: %q, want %q", got, want)
+ }
+ })
+
+ t.Run("bad concrete type", func(t *testing.T) {
+ if errors.Is(wrappedErr, syscall.ENOTRECOVERABLE) {
+ t.Error("incorrect type assertion")
+ }
+ })
+ })
}
type panicWriter struct{}