diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-21 21:59:07 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-22 19:27:31 +0900 |
| commit | 09d284498109b847da0da1e2c5f883268a7f2d46 (patch) | |
| tree | 3784dee4b4e4ec97a95cb222c70d05463ae640ef /container/msg.go | |
| parent | d500d6e55917e12a3f98b39cf0d29b6c96de9667 (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.go')
| -rw-r--r-- | container/msg.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/container/msg.go b/container/msg.go index 3f29e99b..f66c8045 100644 --- a/container/msg.go +++ b/container/msg.go @@ -1,8 +1,13 @@ package container import ( + "errors" + "fmt" "log" + "os" + "reflect" "sync/atomic" + "testing" ) type Msg interface { @@ -32,7 +37,27 @@ func (msg *DefaultMsg) Verbosef(format string, v ...any) { } } +// checkedWrappedErr implements error with strict checks for wrapped values. +type checkedWrappedErr struct { + err error + a []any +} + +func (c *checkedWrappedErr) Error() string { return fmt.Sprintf("%v, a = %s", c.err, c.a) } +func (c *checkedWrappedErr) Is(err error) bool { + var concreteErr *checkedWrappedErr + if !errors.As(err, &concreteErr) { + return false + } + return reflect.DeepEqual(c, concreteErr) +} + func (msg *DefaultMsg) WrapErr(err error, a ...any) error { + // provide a mostly bulletproof path to bypass this behaviour in tests + if testing.Testing() && os.Getenv("GOPATH") != Nonexistent { + return &checkedWrappedErr{err, a} + } + log.Println(a...) return err } |
