github.com/hy3/cuto@v0.9.8-0.20160830082821-aa6652f877b7/util/proc_test.go (about) 1 package util 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func TestIsProcessExists_ReturnTrueWhenExists(t *testing.T) { 9 cmd := createSleepCommand(5) 10 err := cmd.Start() 11 if err != nil { 12 t.Fatalf("Cannot start sleep process.") 13 } 14 defer cmd.Process.Kill() 15 16 if !IsProcessExists(cmd.Process.Pid) { 17 t.Error("IsProcessExists() returns false.") 18 } 19 } 20 21 func TestIsProcessExists_ReturnFalseWhenNotExists(t *testing.T) { 22 cmd := createSleepCommand(0) 23 err := cmd.Run() 24 if err != nil { 25 t.Fatalf("Cannot start sleep process.") 26 } 27 28 time.Sleep(time.Second) 29 30 if IsProcessExists(cmd.Process.Pid) { 31 t.Error("IsProcessExists() returns true.") 32 } 33 }