aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/xhost_test.go
blob: 759f7536daf5e04cb73aa4301112f5e5294d472e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package system

import (
	"testing"

	"hakurei.app/container/stub"
	"hakurei.app/hst"
	"hakurei.app/system/internal/xcb"
)

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

	checkOpBehaviour(t, []opBehaviourTestCase{
		{"xcbChangeHosts revert", 0xbeef, hst.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, hst.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, hst.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", 0xcafe, 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},
	})

	checkOpMeta(t, []opMetaTestCase{
		{"xhost", xhostOp("chronos"), hst.EX11, "/tmp/.X11-unix", "SI:localuser:chronos"},
	})
}