v0.30.0 eb3068f

layershell_preload_test.go RawHistoryFolder

1package bootstrap
2
3import "testing"
4
5func TestShouldPreloadLayerShell_WaylandWithoutPreloadReturnsTrue(t *testing.T) {
6	env := map[string]string{
7		"WAYLAND_DISPLAY": "wayland-1",
8		"LD_PRELOAD":      "",
9	}
10
11	if !ShouldPreloadLayerShell(env) {
12		t.Fatalf("expected preload to be required")
13	}
14}
15
16func TestFindLayerShellLibrary_UsesLDLibraryPathCandidates(t *testing.T) {
17	customCandidate := "/opt/custom/lib/libgtk4-layer-shell.so.0"
18	got := FindLayerShellLibrary(map[string]string{
19		"LD_LIBRARY_PATH": "/opt/custom/lib",
20	}, func(path string) bool {
21		return path == customCandidate
22	})
23
24	if got != customCandidate {
25		t.Fatalf("expected %q, got %q", customCandidate, got)
26	}
27}
28
29func TestShouldPreloadLayerShell_AlreadyPreloadedReturnsFalse(t *testing.T) {
30	env := map[string]string{
31		"WAYLAND_DISPLAY": "wayland-1",
32		"LD_PRELOAD":      "/usr/lib/libgtk4-layer-shell.so.0",
33	}
34
35	if ShouldPreloadLayerShell(env) {
36		t.Fatalf("expected preload to be skipped")
37	}
38}
39
40func TestShouldPreloadLayerShell_NoWaylandReturnsFalse(t *testing.T) {
41	if ShouldPreloadLayerShell(map[string]string{}) {
42		t.Fatalf("expected preload to be skipped outside Wayland")
43	}
44}
45
46func TestLayerShellPreloadPresent_DetectsLoadedLibrarySubstring(t *testing.T) {
47	env := map[string]string{
48		"LD_PRELOAD": "/nix/store/hash-libgtk4-layer-shell.so.0 /tmp/other.so",
49	}
50
51	if !LayerShellPreloadPresent(env) {
52		t.Fatalf("expected preload presence to be detected")
53	}
54}
55
56func TestFindLayerShellLibrary_ReturnsFirstExistingCandidate(t *testing.T) {
57	got := FindLayerShellLibrary(map[string]string{}, func(path string) bool {
58		return path == layerShellLibraryCandidates[1]
59	})
60
61	if got != layerShellLibraryCandidates[1] {
62		t.Fatalf("expected %q, got %q", layerShellLibraryCandidates[1], got)
63	}
64}
65
66func TestFindLayerShellLibrary_ReturnsArm64Candidate(t *testing.T) {
67	arm64Candidate := "/usr/lib/aarch64-linux-gnu/libgtk4-layer-shell.so.0"
68	got := FindLayerShellLibrary(map[string]string{}, func(path string) bool {
69		return path == arm64Candidate
70	})
71
72	if got != arm64Candidate {
73		t.Fatalf("expected %q, got %q", arm64Candidate, got)
74	}
75}
76
77func TestFindLayerShellLibrary_NoMatchReturnsEmpty(t *testing.T) {
78	if got := FindLayerShellLibrary(map[string]string{}, func(string) bool { return false }); got != "" {
79		t.Fatalf("expected empty result, got %q", got)
80	}
81}
82
83func TestLayerShellLibrarySearchPaths_IncludesLDLibraryPathCandidates(t *testing.T) {
84	paths := layerShellLibrarySearchPaths(map[string]string{
85		"LD_LIBRARY_PATH": "/opt/custom/lib:/nix/store/abc/lib",
86	})
87
88	wantCustom := "/opt/custom/lib/libgtk4-layer-shell.so.0"
89	wantNix := "/nix/store/abc/lib/libgtk4-layer-shell.so.0"
90	if !containsString(paths, wantCustom) {
91		t.Fatalf("expected custom search path %q in %#v", wantCustom, paths)
92	}
93	if !containsString(paths, wantNix) {
94		t.Fatalf("expected nix search path %q in %#v", wantNix, paths)
95	}
96}
97
98func TestLayerShellPreloadEnv_SetsLDPreloadWhenEmpty(t *testing.T) {
99	env := LayerShellPreloadEnv(map[string]string{"PATH": "/usr/bin"}, "/usr/lib/libgtk4-layer-shell.so.0")
100
101	if env["LD_PRELOAD"] != "/usr/lib/libgtk4-layer-shell.so.0" {
102		t.Fatalf("expected LD_PRELOAD to be set, got %q", env["LD_PRELOAD"])
103	}
104	if env["PATH"] != "/usr/bin" {
105		t.Fatalf("expected unrelated env to be preserved")
106	}
107}
108
109func TestLayerShellPreloadEnv_PrependsLibraryToExistingLDPreload(t *testing.T) {
110	env := LayerShellPreloadEnv(map[string]string{"LD_PRELOAD": "/tmp/other.so"}, "/usr/lib/libgtk4-layer-shell.so.0")
111
112	want := "/usr/lib/libgtk4-layer-shell.so.0 /tmp/other.so"
113	if env["LD_PRELOAD"] != want {
114		t.Fatalf("expected LD_PRELOAD %q, got %q", want, env["LD_PRELOAD"])
115	}
116}
117
118func containsString(items []string, want string) bool {
119	for _, item := range items {
120		if item == want {
121			return true
122		}
123	}
124	return false
125}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close