将代码与测试注释改为中文以符合仓库规范;新增中文部署指南、 示例配置,并完善构建脚本对 VERSION 注入的说明。 Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
987 B
Go
38 lines
987 B
Go
//go:build linux
|
|
|
|
package service
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"mfd-monitor-agent/internal/config"
|
|
)
|
|
|
|
// TestRenderSystemdUnitIncludesConfigPath 验证安装时保留 -config 参数。
|
|
func TestRenderSystemdUnitIncludesConfigPath(t *testing.T) {
|
|
cfg := config.Default()
|
|
cfg.Service.Description = "MFD Agent"
|
|
|
|
unit := renderSystemdUnit("/opt/agent", "/etc/mfd-agent.json", cfg)
|
|
|
|
if !strings.Contains(unit, "ExecStart=/opt/agent run -config /etc/mfd-agent.json") {
|
|
t.Fatalf("unit missing config path:\n%s", unit)
|
|
}
|
|
}
|
|
|
|
// TestLinuxInstallRequiresRoot 验证 Linux 安装拒绝非 root 调用。
|
|
func TestLinuxInstallRequiresRoot(t *testing.T) {
|
|
oldUID := currentUID
|
|
t.Cleanup(func() { currentUID = oldUID })
|
|
currentUID = func() int { return 1000 }
|
|
|
|
err := linuxManager{}.Install("/opt/agent", config.Default(), InstallOptions{})
|
|
if err == nil {
|
|
t.Fatal("expected root requirement error")
|
|
}
|
|
if !strings.Contains(err.Error(), "root") {
|
|
t.Fatalf("error = %v", err)
|
|
}
|
|
}
|