From 09d284498109b847da0da1e2c5f883268a7f2d46 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 21 Aug 2025 21:59:07 +0900 Subject: 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 --- container/msg_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'container/msg_test.go') 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{} -- cgit v1.3.1