//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) } }