openrazer (the official driver, daemon and library), polychromatic (the AUR tray, kept as found; its i3 line moves out of the i3 module into its own node-display-session contribution), forticlient (the AUR VPN client: its service declared, its configuration never read) and nm-applet (the desktop half of NetworkManager, apart from the server-side module). The openrazer daemon fails on both workstations because the account is not in the openrazer group; openrazer_check names it and the README carries the one-off step, since the account's user resource is zsh's. desktop.go learns to tell a program from another sharing its 15-character command name, so polychromatic's tools never count or end themselves, and a copies test holds the six carriers to one text.
108 lines
3.5 KiB
Go
108 lines
3.5 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func newApplet(t *testing.T, running bool) *fake {
|
|
f := newFake(t)
|
|
f.write("/etc/xdg/autostart/"+entryName, "[Desktop Entry]\nName=Network\nExec=nm-applet\nNotShowIn=KDE;GNOME;\n")
|
|
if running {
|
|
f.proc(3860, 1000, appletComm, []string{"nm-applet"}, "session-c1.scope")
|
|
}
|
|
f.answer = func(name string, args []string) Output {
|
|
switch {
|
|
case name == "pacman":
|
|
return Output{Stdout: "network-manager-applet 1.36.0-2\n"}
|
|
case name == "nmcli":
|
|
return Output{Stdout: "connected:full:enabled:enabled\n"}
|
|
case name == "gsettings":
|
|
return Output{Stdout: "org.gnome.nm-applet disable-connected-notifications false\norg.gnome.nm-applet stamp 0\n" +
|
|
"org.gnome.nm-applet show-applet true\n"}
|
|
case name == "systemctl":
|
|
return Output{Stdout: "active\n"}
|
|
}
|
|
return Output{}
|
|
}
|
|
return f
|
|
}
|
|
|
|
func TestStatusReadsTheAppletAndOnlyTheManagersOverallState(t *testing.T) {
|
|
f := newApplet(t, true)
|
|
s, err := f.Status()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s.Installed != "1.36.0-2" || len(s.Applet) != 1 || !s.StartedBy.Starts || s.Manager == nil ||
|
|
*s.Manager != (Manager{"connected", "full", "enabled", "enabled"}) || len(s.Settings) != 2 || s.Settings["show-applet"] != "true" {
|
|
t.Fatalf("%+v", s)
|
|
}
|
|
for _, c := range f.calls {
|
|
for _, never := range []string{"connection", "device", "secrets", "--show-secrets", " ip"} {
|
|
if strings.HasPrefix(c, "nmcli") && strings.Contains(c, never) {
|
|
t.Fatalf("asked NetworkManager for more than its overall state: %q", c)
|
|
}
|
|
}
|
|
}
|
|
f.answer = func(name string, args []string) Output {
|
|
if name == "nmcli" {
|
|
return Output{Code: 8, Stderr: "Error: NetworkManager is not running."}
|
|
}
|
|
return Output{Stdout: "x 1\n"}
|
|
}
|
|
if s, _ := f.Status(); s.Manager != nil || !strings.Contains(s.Unanswered, "not running") {
|
|
t.Fatalf("%+v", s)
|
|
}
|
|
}
|
|
|
|
func TestCheckPassesThePackagesOneStartAndNamesEveryOther(t *testing.T) {
|
|
f := newApplet(t, true)
|
|
f.desktopSession()
|
|
c, err := f.Check()
|
|
if err != nil || !c.OK || len(c.Starts) != 1 || c.Starts[0] != "XDG autostart: /etc/xdg/autostart/"+entryName {
|
|
t.Fatalf("%+v %v", c, err)
|
|
}
|
|
|
|
f.write(testHome+"/.config/i3/config", "exec --no-startup-id nm-applet --sm-disable\n")
|
|
f.proc(3861, 1000, appletComm, []string{"nm-applet"}, "session-c1.scope")
|
|
f.answer = func(name string, args []string) Output {
|
|
switch name {
|
|
case "pacman":
|
|
return Output{Code: 1}
|
|
case "systemctl":
|
|
return Output{Stdout: "inactive\n", Code: 3}
|
|
}
|
|
return Output{}
|
|
}
|
|
c, _ = f.Check()
|
|
var all []string
|
|
for _, x := range c.Findings {
|
|
all = append(all, x.What)
|
|
}
|
|
got := strings.Join(all, "\n")
|
|
for _, want := range []string{"not installed", "a second start: ~/.config/i3/config:1", "NetworkManager.service", "2 applets run"} {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("no finding %q in\n%s", want, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRestartEndsTheAppletAndStartsItUnderTheServiceManager(t *testing.T) {
|
|
f := newApplet(t, true)
|
|
if _, err := f.Restart(); err == nil || !strings.Contains(err.Error(), "no graphical session") {
|
|
t.Fatalf("without a desktop: %v", err)
|
|
}
|
|
f.desktopSession()
|
|
f.onStart = func(argv []string) { f.proc(9100, 1000, appletComm, argv, "app.slice/"+restartAs+".service") }
|
|
a, err := f.Restart()
|
|
if err != nil || len(a.Ended) != 1 || len(a.Running) != 1 || a.Running[0].Command != appletBin {
|
|
t.Fatalf("%+v %v", a, err)
|
|
}
|
|
for _, c := range f.calls {
|
|
if strings.Contains(c, stackUnit) {
|
|
t.Fatalf("the restart touched NetworkManager: %q", c)
|
|
}
|
|
}
|
|
}
|