File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ type ManagedProcess interface {
35
35
// Status return nil when the process is both alive and owned.
36
36
// If err is non-nil, process may be a) alive but not owned or b) dead.
37
37
Status () error
38
+
39
+ // UnixPid returns the pid of the process. This method returns an error if the pid is
40
+ // unknown. For example, if the process hasn't been `Start`ed yet. Or if not on a unix system.
41
+ UnixPid () (int , error )
38
42
}
39
43
40
44
// NewManagedProcess returns a new, unstarted, from the given configuration.
@@ -107,6 +111,13 @@ func (p *managedProcess) ID() string {
107
111
return p .id
108
112
}
109
113
114
+ func (p * managedProcess ) UnixPid () (int , error ) {
115
+ if p .cmd == nil || p .cmd .Process == nil {
116
+ return 0 , errors .New ("Process not started" )
117
+ }
118
+ return p .cmd .Process .Pid , nil
119
+ }
120
+
110
121
func (p * managedProcess ) Status () error {
111
122
p .mu .Lock ()
112
123
defer p .mu .Unlock ()
Original file line number Diff line number Diff line change @@ -695,3 +695,10 @@ func (fp *fakeProcess) Status() error {
695
695
}
696
696
return nil
697
697
}
698
+
699
+ func (fp * fakeProcess ) UnixPid () (int , error ) {
700
+ return 0 , errors .New (`the NewManagedProcess API needlessly returns an interface
701
+ instead of the structure itself. Thus tests depend on the returned interface. When
702
+ in reality tests should just depend on the methods they rely on. UnixPid is not one
703
+ of those methods (for better or worse)` )
704
+ }
You can’t perform that action at this time.
0 commit comments