package uevent_test

import (
	"syscall"
	"testing"

	"hakurei.app/internal/uevent"
)

func TestKobjectAction(t *testing.T) {
	t.Parallel()

	adeT(t, "add", uevent.KOBJ_ADD, "add", nil, nil)
	adeT(t, "remove", uevent.KOBJ_REMOVE, "remove", nil, nil)
	adeT(t, "change", uevent.KOBJ_CHANGE, "change", nil, nil)
	adeT(t, "move", uevent.KOBJ_MOVE, "move", nil, nil)
	adeT(t, "online", uevent.KOBJ_ONLINE, "online", nil, nil)
	adeT(t, "offline", uevent.KOBJ_OFFLINE, "offline", nil, nil)
	adeT(t, "bind", uevent.KOBJ_BIND, "bind", nil, nil)
	adeT(t, "unbind", uevent.KOBJ_UNBIND, "unbind", nil, nil)

	adeT(t, "unsupported", uevent.KobjectAction(0xbad), "explode",
		uevent.UnsupportedActionError("explode"), syscall.EINVAL)
	t.Run("oob string", func(t *testing.T) {
		t.Parallel()

		const want = "unsupported kobject_action 2989"
		if got := uevent.KobjectAction(0xbad).String(); got != want {
			t.Errorf("String: %q, want %q", got, want)
		}
	})
}
