parent
500edd8745
commit
ae122d5b3e
@ -0,0 +1,55 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAutoStartServiceContentWaitsForGraphicalTarget(t *testing.T) {
|
||||||
|
appPath := filepath.Join("/opt", "tgk-touch", "m9zCtrlTty")
|
||||||
|
content := autoStartServiceContent(appPath)
|
||||||
|
|
||||||
|
for _, want := range []string{
|
||||||
|
"Wants=network-online.target",
|
||||||
|
"After=network-online.target graphical.target display-manager.service",
|
||||||
|
"Environment=DISPLAY=:0",
|
||||||
|
"WantedBy=graphical.target",
|
||||||
|
} {
|
||||||
|
if !strings.Contains(content, want) {
|
||||||
|
t.Fatalf("service content missing %q:\n%s", want, content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAutoStartServiceMatchesRejectsOldNetworkOnlyService(t *testing.T) {
|
||||||
|
appPath := filepath.Join("/opt", "tgk-touch", "m9zCtrlTty")
|
||||||
|
oldContent := `[Unit]
|
||||||
|
Description=m9zCtrlTty Background Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=` + appPath + `
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=10
|
||||||
|
User=root
|
||||||
|
WorkingDirectory=` + filepath.Dir(appPath) + `
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
`
|
||||||
|
|
||||||
|
if autoStartServiceMatches(oldContent, appPath) {
|
||||||
|
t.Fatal("old network-only service should be treated as mismatched")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAutoStartServiceMatchesGeneratedContent(t *testing.T) {
|
||||||
|
appPath := filepath.Join("/opt", "tgk-touch", "m9zCtrlTty")
|
||||||
|
content := autoStartServiceContent(appPath)
|
||||||
|
|
||||||
|
if !autoStartServiceMatches(content, appPath) {
|
||||||
|
t.Fatalf("generated service content should match:\n%s", content)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestDebPackageName(t *testing.T) {
|
||||||
|
tests := map[string]string{
|
||||||
|
"firefox_120.0_arm64.deb": "firefox",
|
||||||
|
"libgtk-3-0_3.22.30_arm64.deb": "libgtk-3-0",
|
||||||
|
"firefox.deb": "firefox",
|
||||||
|
"plain-package": "plain-package",
|
||||||
|
}
|
||||||
|
|
||||||
|
for input, want := range tests {
|
||||||
|
if got := debPackageName(input); got != want {
|
||||||
|
t.Fatalf("debPackageName(%q) = %q, want %q", input, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnsafeFirefoxDebPackages(t *testing.T) {
|
||||||
|
packages := []string{
|
||||||
|
"firefox",
|
||||||
|
"libgtk-3-0",
|
||||||
|
"dpkg",
|
||||||
|
"coreutils",
|
||||||
|
"libc6",
|
||||||
|
"tar",
|
||||||
|
"dpkg",
|
||||||
|
}
|
||||||
|
want := []string{"coreutils", "dpkg", "libc6", "tar"}
|
||||||
|
|
||||||
|
got := unsafeFirefoxDebPackages(packages)
|
||||||
|
if !stringSlicesEqual(got, want) {
|
||||||
|
t.Fatalf("unsafeFirefoxDebPackages() = %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringSlicesEqual(left []string, right []string) bool {
|
||||||
|
if len(left) != len(right) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := range left {
|
||||||
|
if left[i] != right[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
Loading…
Reference in new issue