aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/uevent/uevent_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-27 22:37:36 +0900
committerOphestra <cat@gensokyo.uk>2026-03-27 22:39:43 +0900
commitee22847dde5c02027a4f180f1f32a69adc3aaf70 (patch)
treec1cdd5a0b546cfe2903e197c4658098960a67254 /internal/uevent/uevent_test.go
parentc61188649b757ba81c813ff2f7351a3d393cdce1 (diff)
internal/uevent: kobject_action lookup
This is encoded as part of kobject uevent message headers. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/uevent/uevent_test.go')
-rw-r--r--internal/uevent/uevent_test.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/internal/uevent/uevent_test.go b/internal/uevent/uevent_test.go
new file mode 100644
index 00000000..9af3dcdd
--- /dev/null
+++ b/internal/uevent/uevent_test.go
@@ -0,0 +1,83 @@
+package uevent_test
+
+import (
+ "encoding"
+ "fmt"
+ "reflect"
+ "testing"
+
+ "hakurei.app/internal/uevent"
+)
+
+// adeT sets up a parallel subtest for a textual appender/decoder/encoder.
+func adeT[V any, S interface {
+ encoding.TextAppender
+ encoding.TextMarshaler
+ encoding.TextUnmarshaler
+ fmt.Stringer
+
+ *V
+}](t *testing.T, name string, v V, want string, wantErr, wantErrE error) {
+ t.Helper()
+ t.Run(name, func(t *testing.T) {
+ t.Parallel()
+ t.Helper()
+
+ t.Run("decode", func(t *testing.T) {
+ t.Parallel()
+ t.Helper()
+
+ var got V
+ if err := S(&got).UnmarshalText([]byte(want)); !reflect.DeepEqual(err, wantErr) {
+ t.Fatalf("UnmarshalText: error = %v, want %v", err, wantErr)
+ }
+ if wantErr != nil {
+ return
+ }
+
+ if !reflect.DeepEqual(&got, &v) {
+ t.Errorf("UnmarshalText: %#v, want %#v", got, v)
+ }
+ })
+
+ t.Run("encode", func(t *testing.T) {
+ t.Parallel()
+ t.Helper()
+
+ if got, err := S(&v).MarshalText(); !reflect.DeepEqual(err, wantErrE) {
+ t.Fatalf("MarshalText: error = %v, want %v", err, wantErrE)
+ } else if err == nil && string(got) != want {
+ t.Errorf("MarshalText: %q, want %q", string(got), want)
+ }
+ if wantErrE != nil {
+ return
+ }
+
+ if got := S(&v).String(); got != want {
+ t.Errorf("String: %q, want %q", got, want)
+ }
+ })
+ })
+}
+
+func TestErrors(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ name string
+ err error
+ want string
+ }{
+ {"UnsupportedActionError", uevent.UnsupportedActionError("explode"),
+ `unsupported kobject_action "explode"`},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+
+ if got := tc.err.Error(); got != tc.want {
+ t.Errorf("Error: %q, want %q", got, tc.want)
+ }
+ })
+ }
+}