* 实现周期采集、快照缓存、本地 HTTP API 和主动上报 * 补齐 Linux 和 Windows 主机、网络、资源、进程和 TCP 采集 * 添加服务生命周期管理、配置加载、构建脚本和测试覆盖 BREAKING CHANGE: network.ips 拆分为 network.ipv4s 和 network.ipv6s。
38 lines
996 B
Go
38 lines
996 B
Go
//go:build linux
|
|
|
|
package service
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"mfd-monitor-agent/internal/config"
|
|
)
|
|
|
|
// TestRenderSystemdUnitIncludesConfigPath verifies install preserves the config flag.
|
|
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 verifies Linux install rejects non-root callers.
|
|
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)
|
|
}
|
|
}
|