system: remove test package
All checks were successful
Test / Create distribution (push) Successful in 45s
Test / Sandbox (push) Successful in 2m28s
Test / Hakurei (push) Successful in 3m35s
Test / Hpkg (push) Successful in 4m17s
Test / Sandbox (race detector) (push) Successful in 4m41s
Test / Hakurei (race detector) (push) Successful in 5m26s
Test / Flake checks (push) Successful in 1m25s

This prepares the Commit and Revert methods for testing via stub.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-09-10 23:50:22 +09:00
parent 985c4dd2fc
commit 8df01b71d4
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q

View File

@ -1,35 +1,28 @@
package system_test package system
import ( import (
"reflect"
"strconv" "strconv"
"testing" "testing"
_ "unsafe"
"hakurei.app/system"
) )
//go:linkname criteriaHasType hakurei.app/system.(*Criteria).hasType
func criteriaHasType(_ *system.Criteria, _ system.Enablement) bool
func TestCriteria(t *testing.T) { func TestCriteria(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
ec, t system.Enablement ec, t Enablement
want bool want bool
}{ }{
{"nil", 0xff, system.EWayland, true}, {"nil", 0xff, EWayland, true},
{"nil user", 0xff, system.User, false}, {"nil user", 0xff, User, false},
{"all", system.EWayland | system.EX11 | system.EDBus | system.EPulse | system.User | system.Process, system.Process, true}, {"all", EWayland | EX11 | EDBus | EPulse | User | Process, Process, true},
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
var criteria *system.Criteria var criteria *Criteria
if tc.ec != 0xff { if tc.ec != 0xff {
criteria = (*system.Criteria)(&tc.ec) criteria = (*Criteria)(&tc.ec)
} }
if got := criteriaHasType(criteria, tc.t); got != tc.want { if got := criteria.hasType(tc.t); got != tc.want {
t.Errorf("hasType: got %v, want %v", t.Errorf("hasType: got %v, want %v",
got, tc.want) got, tc.want)
} }
@ -39,23 +32,23 @@ func TestCriteria(t *testing.T) {
func TestTypeString(t *testing.T) { func TestTypeString(t *testing.T) {
testCases := []struct { testCases := []struct {
e system.Enablement e Enablement
want string want string
}{ }{
{system.EWayland, system.EWayland.String()}, {EWayland, EWayland.String()},
{system.EX11, system.EX11.String()}, {EX11, EX11.String()},
{system.EDBus, system.EDBus.String()}, {EDBus, EDBus.String()},
{system.EPulse, system.EPulse.String()}, {EPulse, EPulse.String()},
{system.User, "user"}, {User, "user"},
{system.Process, "process"}, {Process, "process"},
{system.User | system.Process, "user, process"}, {User | Process, "user, process"},
{system.EWayland | system.User | system.Process, "wayland, user, process"}, {EWayland | User | Process, "wayland, user, process"},
{system.EX11 | system.Process, "x11, process"}, {EX11 | Process, "x11, process"},
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run("label type string "+strconv.Itoa(int(tc.e)), func(t *testing.T) { t.Run("label type string "+strconv.Itoa(int(tc.e)), func(t *testing.T) {
if got := system.TypeString(tc.e); got != tc.want { if got := TypeString(tc.e); got != tc.want {
t.Errorf("TypeString: %q, want %q", got, tc.want) t.Errorf("TypeString: %q, want %q", got, tc.want)
} }
}) })
@ -71,7 +64,7 @@ func TestNew(t *testing.T) {
t.Errorf("recover: %v, want %v", r, want) t.Errorf("recover: %v, want %v", r, want)
} }
}() }()
system.New(nil, 0) New(nil, 0)
}) })
t.Run("uid", func(t *testing.T) { t.Run("uid", func(t *testing.T) {
@ -81,13 +74,13 @@ func TestNew(t *testing.T) {
t.Errorf("recover: %v, want %v", r, want) t.Errorf("recover: %v, want %v", r, want)
} }
}() }()
system.New(t.Context(), -1) New(t.Context(), -1)
}) })
}) })
sys := system.New(t.Context(), 0xdeadbeef) sys := New(t.Context(), 0xdeadbeef)
if got := reflect.ValueOf(sys).Elem().FieldByName("ctx"); got.IsNil() { if sys.ctx == nil {
t.Errorf("New: ctx = %#v", got) t.Error("New: ctx = nil")
} }
if got := sys.UID(); got != 0xdeadbeef { if got := sys.UID(); got != 0xdeadbeef {
t.Errorf("UID: %d", got) t.Errorf("UID: %d", got)
@ -97,56 +90,56 @@ func TestNew(t *testing.T) {
func TestEqual(t *testing.T) { func TestEqual(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
sys *system.I sys *I
v *system.I v *I
want bool want bool
}{ }{
{"simple UID", {"simple UID",
system.New(t.Context(), 150), New(t.Context(), 150),
system.New(t.Context(), 150), New(t.Context(), 150),
true}, true},
{"simple UID differ", {"simple UID differ",
system.New(t.Context(), 150), New(t.Context(), 150),
system.New(t.Context(), 151), New(t.Context(), 151),
false}, false},
{"simple UID nil", {"simple UID nil",
system.New(t.Context(), 150), New(t.Context(), 150),
nil, nil,
false}, false},
{"op length mismatch", {"op length mismatch",
system.New(t.Context(), 150). New(t.Context(), 150).
ChangeHosts("chronos"), ChangeHosts("chronos"),
system.New(t.Context(), 150). New(t.Context(), 150).
ChangeHosts("chronos"). ChangeHosts("chronos").
Ensure("/run", 0755), Ensure("/run", 0755),
false}, false},
{"op value mismatch", {"op value mismatch",
system.New(t.Context(), 150). New(t.Context(), 150).
ChangeHosts("chronos"). ChangeHosts("chronos").
Ensure("/run", 0644), Ensure("/run", 0644),
system.New(t.Context(), 150). New(t.Context(), 150).
ChangeHosts("chronos"). ChangeHosts("chronos").
Ensure("/run", 0755), Ensure("/run", 0755),
false}, false},
{"op type mismatch", {"op type mismatch",
system.New(t.Context(), 150). New(t.Context(), 150).
ChangeHosts("chronos"). ChangeHosts("chronos").
CopyFile(new([]byte), "/home/ophestra/xdg/config/pulse/cookie", 0, 256), CopyFile(new([]byte), "/home/ophestra/xdg/config/pulse/cookie", 0, 256),
system.New(t.Context(), 150). New(t.Context(), 150).
ChangeHosts("chronos"). ChangeHosts("chronos").
Ensure("/run", 0755), Ensure("/run", 0755),
false}, false},
{"op equals", {"op equals",
system.New(t.Context(), 150). New(t.Context(), 150).
ChangeHosts("chronos"). ChangeHosts("chronos").
Ensure("/run", 0755), Ensure("/run", 0755),
system.New(t.Context(), 150). New(t.Context(), 150).
ChangeHosts("chronos"). ChangeHosts("chronos").
Ensure("/run", 0755), Ensure("/run", 0755),
true}, true},