62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
//go:build linux
|
||
|
||
package main
|
||
|
||
import "testing"
|
||
|
||
func TestLinuxStartupChannelsPriorityAndArguments(t *testing.T) {
|
||
t.Setenv("DISPLAY", ":0")
|
||
t.Setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path=/tmp/dbus")
|
||
runner := &fakeCommandRunner{paths: map[string]bool{
|
||
"notify-send": true,
|
||
"kdialog": true,
|
||
"zenity": true,
|
||
"xmessage": true,
|
||
}}
|
||
|
||
channels := platformStartupChannels(runner)
|
||
if len(channels) != 5 {
|
||
t.Fatalf("Linux 应有 5 个 UI 通道,实际: %d", len(channels))
|
||
}
|
||
|
||
req := promptRequest{title: "Nex 启动失败", message: "端口被占用"}
|
||
for _, channel := range channels {
|
||
if err := channel.available(); err != nil {
|
||
t.Fatalf("通道 %s 应可用: %v", channel.name, err)
|
||
}
|
||
if err := channel.run(req); err != nil {
|
||
t.Fatalf("通道 %s 执行失败: %v", channel.name, err)
|
||
}
|
||
}
|
||
|
||
wantNames := []string{"notify-send", "kdialog", "zenity", "kdialog", "xmessage"}
|
||
for i, want := range wantNames {
|
||
if got := runner.calls[i].name; got != want {
|
||
t.Fatalf("第 %d 个命令 = %s, want %s", i, got, want)
|
||
}
|
||
}
|
||
if got := runner.calls[0].args; len(got) < 2 || got[0] != "-u" || got[1] != "critical" {
|
||
t.Fatalf("notify-send 应使用 critical 参数,实际: %#v", got)
|
||
}
|
||
if got := runner.calls[1].args; len(got) < 3 || got[2] != "--passivepopup" {
|
||
t.Fatalf("kdialog 第一跳应使用 passivepopup,实际: %#v", got)
|
||
}
|
||
if got := runner.calls[2].args; len(got) < 1 || got[0] != "--error" {
|
||
t.Fatalf("zenity 应使用 --error,实际: %#v", got)
|
||
}
|
||
if got := runner.calls[4].args; len(got) < 1 || got[0] != "-center" {
|
||
t.Fatalf("xmessage 应居中显示,实际: %#v", got)
|
||
}
|
||
}
|
||
|
||
func TestLinuxNotifySendRequiresDBus(t *testing.T) {
|
||
t.Setenv("DISPLAY", ":0")
|
||
t.Setenv("DBUS_SESSION_BUS_ADDRESS", "")
|
||
runner := &fakeCommandRunner{paths: map[string]bool{"notify-send": true}}
|
||
|
||
channels := platformStartupChannels(runner)
|
||
if err := channels[0].available(); err == nil {
|
||
t.Fatal("notify-send 缺少 DBus session bus 时应不可用")
|
||
}
|
||
}
|