- 新增自启动幂等配置、统一错误语义、进程等待和进程树终止能力 - 增强服务生命周期管理,支持等待状态、重启、幂等创建和配置更新 - 新增 NTFS 卷索引、文件 ID 解析、文件遍历、USN 变更监听和 bookmark 持久化 - 修复 NTFS boot sector、fragment、MFT、USN 解析边界和路径重建问题 - 补充权限、进程、服务、NTFS 解析和工作流回归测试 - 增加 Windows 测试脚本和管理员 NTFS smoke 验证脚本 - 升级 Go 兼容版本到 1.18,并更新 stario、win32api 及相关间接依赖
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package wincmd
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsProcessRunningByPIDCurrentProcess(t *testing.T) {
|
|
ok, err := IsProcessRunningByPID(os.Getpid())
|
|
if err != nil {
|
|
t.Fatalf("IsProcessRunningByPID returned error: %v", err)
|
|
}
|
|
if !ok {
|
|
t.Fatal("expected current process pid to be reported as running")
|
|
}
|
|
}
|
|
|
|
func TestGetRunningProcessContainsCurrentProcess(t *testing.T) {
|
|
list, err := GetRunningProcess()
|
|
if err != nil {
|
|
t.Fatalf("GetRunningProcess returned error: %v", err)
|
|
}
|
|
if len(list) == 0 {
|
|
t.Fatal("expected process list to be non-empty")
|
|
}
|
|
|
|
wantPID := strconv.Itoa(os.Getpid())
|
|
found := false
|
|
for _, item := range list {
|
|
if item["pid"] == wantPID {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("expected process list to contain current pid %s", wantPID)
|
|
}
|
|
}
|
|
|
|
func TestProcessNameQueriesForCurrentExecutable(t *testing.T) {
|
|
exe, err := os.Executable()
|
|
if err != nil {
|
|
t.Fatalf("os.Executable failed: %v", err)
|
|
}
|
|
name := filepath.Base(exe)
|
|
|
|
ok, err := IsProcessRunning(name)
|
|
if err != nil {
|
|
t.Fatalf("IsProcessRunning returned error: %v", err)
|
|
}
|
|
if !ok {
|
|
t.Fatalf("expected process %q to be running", name)
|
|
}
|
|
|
|
count, err := GetProcessCount(name)
|
|
if err != nil {
|
|
t.Fatalf("GetProcessCount returned error: %v", err)
|
|
}
|
|
if count <= 0 {
|
|
t.Fatalf("expected process count > 0 for %q, got %d", name, count)
|
|
}
|
|
}
|