Skip to content

Commit 0e0a72f

Browse files
committed
updated FindPid and associated test
1 parent 7fee4d3 commit 0e0a72f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

process.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ func (p *Process) StartTty(ttyFd uintptr, notify chan<- struct{}) error {
129129
// FindPid finds and then sets the a process's pid based
130130
// on it's command, it's command's arguments and it's tty.
131131
func (p *Process) FindPid() error {
132+
if p.Process == nil {
133+
p.Process = &os.Process{}
134+
}
135+
132136
if p.Cmd == "" {
133137
return fmt.Errorf("process command is empty")
134138
}

process_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ func TestFullCommand(t *testing.T) {
110110
}
111111

112112
func TestFindPid(t *testing.T) {
113-
proc := &Process{Cwd: cwd, Cmd: cmd, Args: args, Tty: currentTty, Process: &os.Process{}}
113+
proc := &Process{
114+
Cmd: cmd,
115+
Args: args,
116+
Tty: currentTty,
117+
}
118+
114119
if err := proc.FindPid(); err != nil {
115120
t.Error(err)
116121
}

0 commit comments

Comments
 (0)