修改代码注释为中文

This commit is contained in:
zyj
2026-03-04 14:10:30 +08:00
parent 89d64cb117
commit 2cb4e1a87b
16 changed files with 1031 additions and 69 deletions

View File

@@ -11,13 +11,13 @@ func TestRegistry_Register(t *testing.T) {
mock := &mockCollector{name: "test"}
err := r.Register(mock)
if err != nil {
t.Fatalf("unexpected error: %v", err)
t.Fatalf("注册时不应出错: %v", err)
}
// Duplicate registration should fail
// 重复注册应该失败
err = r.Register(mock)
if err == nil {
t.Fatal("expected error for duplicate registration")
t.Fatal("重复注册应该返回错误")
}
}
@@ -29,15 +29,15 @@ func TestRegistry_Get(t *testing.T) {
c, ok := r.Get("test")
if !ok {
t.Fatal("expected to find collector")
t.Fatal("应该能找到已注册的采集器")
}
if c.Name() != "test" {
t.Fatalf("expected name 'test', got '%s'", c.Name())
t.Fatalf("期望名称为 'test',实际为 '%s'", c.Name())
}
_, ok = r.Get("nonexistent")
if ok {
t.Fatal("expected not to find collector")
t.Fatal("不应该找到未注册的采集器")
}
}
@@ -50,16 +50,16 @@ func TestRegistry_List(t *testing.T) {
all := r.List()
if len(all) != 3 {
t.Fatalf("expected 3 collectors, got %d", len(all))
t.Fatalf("期望 3 个采集器,实际为 %d", len(all))
}
runtime := r.ListByCategory(CategoryRuntime)
if len(runtime) != 2 {
t.Fatalf("expected 2 runtime collectors, got %d", len(runtime))
t.Fatalf("期望 2 个运行时采集器,实际为 %d", len(runtime))
}
}
// mockCollector implements Collector for testing
// mockCollector 用于测试的模拟采集器
type mockCollector struct {
name string
category Category
@@ -68,7 +68,7 @@ type mockCollector struct {
func (m *mockCollector) Name() string { return m.name }
func (m *mockCollector) DisplayName() string { return m.name }
func (m *mockCollector) Description() string { return "mock collector" }
func (m *mockCollector) Description() string { return "模拟采集器" }
func (m *mockCollector) Category() Category { return m.category }
func (m *mockCollector) IsAvailable(ctx context.Context) bool {
return m.available

View File

@@ -18,7 +18,7 @@ func NewDarwinPlatform() *DarwinPlatform {
}
func (p *DarwinPlatform) OS() string { return "darwin" }
func (p *DarwinPlatform) Arch() string { return "amd64" } // TODO: detect properly
func (p *DarwinPlatform) Arch() string { return "amd64" } // TODO: 正确检测架构
func (p *DarwinPlatform) HomeDir() string { return p.homeDir }
func (p *DarwinPlatform) ConfigDir() string {
@@ -34,13 +34,13 @@ func (p *DarwinPlatform) GetEnvVar(key string) string {
}
func (p *DarwinPlatform) SetEnvVar(ctx context.Context, key, value string) error {
// On macOS, set via launchctl and shell profile
// macOS 上通过 launchctl 和 Shell 配置文件设置
cmd := exec.CommandContext(ctx, "launchctl", "setenv", key, value)
return cmd.Run()
}
func (p *DarwinPlatform) AddToPath(ctx context.Context, dir string) error {
// TODO: Add to shell profile
// TODO: 添加到 Shell 配置文件
return nil
}

View File

@@ -18,7 +18,7 @@ func NewLinuxPlatform() *LinuxPlatform {
}
func (p *LinuxPlatform) OS() string { return "linux" }
func (p *LinuxPlatform) Arch() string { return "amd64" } // TODO: detect properly
func (p *LinuxPlatform) Arch() string { return "amd64" } // TODO: 正确检测架构
func (p *LinuxPlatform) HomeDir() string { return p.homeDir }
func (p *LinuxPlatform) ConfigDir() string {
@@ -40,12 +40,12 @@ func (p *LinuxPlatform) GetEnvVar(key string) string {
}
func (p *LinuxPlatform) SetEnvVar(ctx context.Context, key, value string) error {
// TODO: Add to shell profile
// TODO: 写入 Shell 配置文件以持久化
return os.Setenv(key, value)
}
func (p *LinuxPlatform) AddToPath(ctx context.Context, dir string) error {
// TODO: Add to shell profile
// TODO: 添加到 Shell 配置文件
return nil
}

View File

@@ -51,7 +51,7 @@ func Detect() Platform {
case "linux":
return NewLinuxPlatform()
default:
// Fallback to Linux
// 默认回退到 Linux 实现
return NewLinuxPlatform()
}
}

View File

@@ -55,7 +55,7 @@ func (p *WindowsPlatform) AddToPath(ctx context.Context, dir string) error {
}
func (p *WindowsPlatform) IsAdmin() bool {
// Check if running as administrator on Windows
// 检查 Windows 上是否以管理员身份运行
cmd := exec.Command("net", "session")
err := cmd.Run()
return err == nil
@@ -77,7 +77,7 @@ func (p *WindowsPlatform) PackageManagers() []string {
func (p *WindowsPlatform) DefaultShell() string {
if _, err := exec.LookPath("pwsh"); err == nil {
return "pwsh" // PowerShell 7+
return "pwsh" // PowerShell 7+ 版本
}
return "powershell" // Windows PowerShell 5.1
}