-
Notifications
You must be signed in to change notification settings - Fork 16
/
tree_utils_test.go
118 lines (95 loc) · 2.45 KB
/
tree_utils_test.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package i3
import (
"context"
"os"
"os/exec"
"testing"
)
// TestTreeUtilsSubprocess runs in a process which has been started with
// DISPLAY= pointing to an Xvfb instance with i3 -c testdata/i3.config running.
func TestTreeUtilsSubprocess(t *testing.T) {
if os.Getenv("GO_WANT_XVFB") != "1" {
t.Skip("parent process")
}
mark_name := "foo"
ws_name := "1:test_space"
if _, err := RunCommand("rename workspace to " + ws_name); err != nil {
t.Fatal(err)
}
if _, err := RunCommand("open; mark " + mark_name); err != nil {
t.Fatal(err)
}
t.Run("FindParent", func(t *testing.T) {
t.Parallel()
got, err := GetTree()
if err != nil {
t.Fatal(err)
}
node := got.Root.FindFocused(func(n *Node) bool { return n.Focused })
if node == nil {
t.Fatal("unexpectedly could not find any focused node in GetTree reply")
}
// Exercise FindParent to locate parent for given node.
parent := node.FindParent()
if parent == nil {
t.Fatal("no parent found")
}
if parent.Name != ws_name {
t.Fatal("wrong parent found: " + parent.Name)
}
})
t.Run("IsFloating", func(t *testing.T) {
// do not run in parallel because 'floating toggle' breaks other tests
got, err := GetTree()
if err != nil {
t.Fatal(err)
}
node := got.Root.FindFocused(func(n *Node) bool { return n.Focused })
if node == nil {
t.Fatal("unexpectedly could not find any focused node in GetTree reply")
}
if node.IsFloating() == true {
t.Fatal("node is floating")
}
if _, err := RunCommand("floating toggle"); err != nil {
t.Fatal(err)
}
got, err = GetTree()
if err != nil {
t.Fatal(err)
}
node = got.Root.FindFocused(func(n *Node) bool { return n.Focused })
if node == nil {
t.Fatal("unexpectedly could not find any focused node in GetTree reply")
}
if node.IsFloating() == false {
t.Fatal("node is not floating")
}
RunCommand("floating toggle")
})
}
func TestTreeUtils(t *testing.T) {
t.Parallel()
ctx, canc := context.WithCancel(context.Background())
defer canc()
_, DISPLAY, err := launchXvfb(ctx)
if err != nil {
t.Fatal(err)
}
cleanup, err := launchI3(ctx, DISPLAY, "")
if err != nil {
t.Fatal(err)
}
defer cleanup()
cmd := exec.Command(os.Args[0], "-test.run=TestTreeUtilsSubprocess", "-test.v")
cmd.Env = []string{
"GO_WANT_XVFB=1",
"DISPLAY=" + DISPLAY,
"PATH=" + os.Getenv("PATH"),
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
t.Fatal(err.Error())
}
}