aboutsummaryrefslogtreecommitdiffhomepage
path: root/ext/ext_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-17 13:35:48 +0900
committerOphestra <cat@gensokyo.uk>2026-03-17 13:39:26 +0900
commitcd5959fe5ab04786cd5dee3cf09f725229ae7c7b (patch)
treec0dae3f950528e7c3b6d7359441ee8aeb9a488cd /ext/ext_test.go
parent08c35ca24fabc41268411cec14ea386a6d87ece9 (diff)
ext: isolate from container/std
These are too general to belong in the container package. This targets the v0.4 release to reduce the wrapper maintenance burden. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ext/ext_test.go')
-rw-r--r--ext/ext_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/ext/ext_test.go b/ext/ext_test.go
new file mode 100644
index 00000000..e6d7f579
--- /dev/null
+++ b/ext/ext_test.go
@@ -0,0 +1,62 @@
+package ext_test
+
+import (
+ "encoding/json"
+ "errors"
+ "math"
+ "reflect"
+ "testing"
+
+ "hakurei.app/ext"
+)
+
+func TestSyscall(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ name string
+ data string
+ want ext.SyscallNum
+ err error
+ }{
+ {"epoll_create1", `"epoll_create1"`, ext.SNR_EPOLL_CREATE1, nil},
+ {"clone3", `"clone3"`, ext.SNR_CLONE3, nil},
+
+ {"oob", `-2147483647`, -math.MaxInt32,
+ &json.UnmarshalTypeError{Value: "number", Type: reflect.TypeFor[string](), Offset: 11}},
+ {"name", `"nonexistent_syscall"`, -math.MaxInt32,
+ ext.SyscallNameError("nonexistent_syscall")},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+
+ t.Run("decode", func(t *testing.T) {
+ var got ext.SyscallNum
+ if err := json.Unmarshal([]byte(tc.data), &got); !reflect.DeepEqual(err, tc.err) {
+ t.Fatalf("Unmarshal: error = %#v, want %#v", err, tc.err)
+ } else if err == nil && got != tc.want {
+ t.Errorf("Unmarshal: %v, want %v", got, tc.want)
+ }
+ })
+ if errors.As(tc.err, new(ext.SyscallNameError)) {
+ return
+ }
+
+ t.Run("encode", func(t *testing.T) {
+ if got, err := json.Marshal(&tc.want); err != nil {
+ t.Fatalf("Marshal: error = %v", err)
+ } else if string(got) != tc.data {
+ t.Errorf("Marshal: %s, want %s", string(got), tc.data)
+ }
+ })
+ })
+ }
+
+ t.Run("error", func(t *testing.T) {
+ const want = `invalid syscall name "\x00"`
+ if got := ext.SyscallNameError("\x00").Error(); got != want {
+ t.Fatalf("Error: %q, want %q", got, want)
+ }
+ })
+}