diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-08 04:17:39 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-08 04:17:39 +0900 |
| commit | 985c4dd2fc175d8c52304ee387a71e7d855b421a (patch) | |
| tree | 8f487bf3786bbe53a6302bbd9e84dc5ad342b073 /system/xhost_test.go | |
| parent | da2b9c01ceac2d55c271de46d7d18e5b3f19b89b (diff) | |
system/xhost: wrap revert error correctly
This otherwise creates a confusing error message on a revert failure.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/xhost_test.go')
| -rw-r--r-- | system/xhost_test.go | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/system/xhost_test.go b/system/xhost_test.go index 32cb0636..68601e86 100644 --- a/system/xhost_test.go +++ b/system/xhost_test.go @@ -2,33 +2,56 @@ package system import ( "testing" + + "hakurei.app/container/stub" + "hakurei.app/system/internal/xcb" ) -func TestChangeHosts(t *testing.T) { - testCases := []string{"chronos", "keyring", "cat", "kbd", "yonah"} - for _, tc := range testCases { - t.Run("append ChangeHosts operation for "+tc, func(t *testing.T) { - sys := New(t.Context(), 150) - sys.ChangeHosts(tc) - (&tcOp{EX11, tc}).test(t, sys.ops, []Op{ - xhostOp(tc), - }, "ChangeHosts") - }) - } -} +func TestXHostOp(t *testing.T) { + checkOpBehaviour(t, []opBehaviourTestCase{ + {"xcbChangeHosts revert", 0xbeef, EX11, xhostOp("chronos"), []stub.Call{ + call("verbosef", stub.ExpectArgs{"inserting entry %s to X11", []any{xhostOp("chronos")}}, nil, nil), + call("xcbChangeHosts", stub.ExpectArgs{xcb.HostMode(xcb.HostModeInsert), xcb.Family(xcb.FamilyServerInterpreted), "localuser\x00chronos"}, nil, stub.UniqueError(1)), + }, &OpError{Op: "xhost", Err: stub.UniqueError(1)}, nil, nil}, + + {"xcbChangeHosts revert", 0xbeef, EX11, xhostOp("chronos"), []stub.Call{ + call("verbosef", stub.ExpectArgs{"inserting entry %s to X11", []any{xhostOp("chronos")}}, nil, nil), + call("xcbChangeHosts", stub.ExpectArgs{xcb.HostMode(xcb.HostModeInsert), xcb.Family(xcb.FamilyServerInterpreted), "localuser\x00chronos"}, nil, nil), + }, nil, []stub.Call{ + call("verbosef", stub.ExpectArgs{"deleting entry %s from X11", []any{xhostOp("chronos")}}, nil, nil), + call("xcbChangeHosts", stub.ExpectArgs{xcb.HostMode(xcb.HostModeDelete), xcb.Family(xcb.FamilyServerInterpreted), "localuser\x00chronos"}, nil, stub.UniqueError(0)), + }, &OpError{Op: "xhost", Err: stub.UniqueError(0), Revert: true}}, + + {"success skip", 0xbeef, 0, xhostOp("chronos"), []stub.Call{ + call("verbosef", stub.ExpectArgs{"inserting entry %s to X11", []any{xhostOp("chronos")}}, nil, nil), + call("xcbChangeHosts", stub.ExpectArgs{xcb.HostMode(xcb.HostModeInsert), xcb.Family(xcb.FamilyServerInterpreted), "localuser\x00chronos"}, nil, nil), + }, nil, []stub.Call{ + call("verbosef", stub.ExpectArgs{"skipping entry %s in X11", []any{xhostOp("chronos")}}, nil, nil), + }, nil}, + + {"success", 0xbeef, EX11, xhostOp("chronos"), []stub.Call{ + call("verbosef", stub.ExpectArgs{"inserting entry %s to X11", []any{xhostOp("chronos")}}, nil, nil), + call("xcbChangeHosts", stub.ExpectArgs{xcb.HostMode(xcb.HostModeInsert), xcb.Family(xcb.FamilyServerInterpreted), "localuser\x00chronos"}, nil, nil), + }, nil, []stub.Call{ + call("verbosef", stub.ExpectArgs{"deleting entry %s from X11", []any{xhostOp("chronos")}}, nil, nil), + call("xcbChangeHosts", stub.ExpectArgs{xcb.HostMode(xcb.HostModeDelete), xcb.Family(xcb.FamilyServerInterpreted), "localuser\x00chronos"}, nil, nil), + }, nil}, + }) + + checkOpsBuilder(t, "ChangeHosts", []opsBuilderTestCase{ + {"xhost", 0xcafebabe, func(_ *testing.T, sys *I) { + sys.ChangeHosts("chronos") + }, []Op{ + xhostOp("chronos"), + }, stub.Expect{}}, + }) + + checkOpIs(t, []opIsTestCase{ + {"differs", xhostOp("kbd"), xhostOp("chronos"), false}, + {"equals", xhostOp("chronos"), xhostOp("chronos"), true}, + }) -func TestXHost_String(t *testing.T) { - testCases := []struct { - username string - want string - }{ - {"chronos", "SI:localuser:chronos"}, - } - for _, tc := range testCases { - t.Run(tc.want, func(t *testing.T) { - if got := xhostOp(tc.username).String(); got != tc.want { - t.Errorf("String() = %v, want %v", got, tc.want) - } - }) - } + checkOpMeta(t, []opMetaTestCase{ + {"xhost", xhostOp("chronos"), EX11, "/tmp/.X11-unix", "SI:localuser:chronos"}, + }) } |
