1package ps 2 3import ( 4 "os" 5 "testing" 6) 7 8func TestFindProcess(t *testing.T) { 9 p, err := FindProcess(os.Getpid()) 10 if err != nil { 11 t.Fatalf("err: %s", err) 12 } 13 if p == nil { 14 t.Fatal("should have process") 15 } 16 17 if p.Pid() != os.Getpid() { 18 t.Fatalf("bad: %#v", p.Pid()) 19 } 20} 21 22func TestProcesses(t *testing.T) { 23 // This test works because there will always be SOME processes 24 // running. 25 p, err := Processes() 26 if err != nil { 27 t.Fatalf("err: %s", err) 28 } 29 30 if len(p) <= 0 { 31 t.Fatal("should have processes") 32 } 33 34 found := false 35 for _, p1 := range p { 36 if p1.Executable() == "go" || p1.Executable() == "go.exe" { 37 found = true 38 break 39 } 40 } 41 42 if !found { 43 t.Fatal("should have Go") 44 } 45} 46