Files
odo/pkg/testingutil/system/fake.go
Philippe Martin 0f828ec99f Ignore devstate when existing process name is not odo + delete devstate files with odo delete component (#7090)
* Ignore devstate when existing process name is not odo

* Delete orphan devstate files with odo delete component

* Update unit tests

* Create fake system

* Add unit tests for odo delete component

* Integration tests for odo dev

* Troubleshooting

* First process on Windows is 4

* Use go-ps lib for pidExists
2023-09-20 14:20:53 +02:00

42 lines
691 B
Go

package system
import (
"errors"
"github.com/mitchellh/go-ps"
)
type Fake struct {
ProcessId int
ParentId int
// PidTable is a map of pid => executable name of existing processes
PidTable map[int]string
}
func (o Fake) Pid() int {
return o.ProcessId
}
func (o Fake) PPid() int {
return o.ParentId
}
func (o Fake) Executable() string {
return o.PidTable[o.ProcessId]
}
var _ System = Fake{}
func (o Fake) FindProcess(pid int) (ps.Process, error) {
if _, found := o.PidTable[pid]; found {
o.ProcessId = pid
return o, nil
}
return nil, errors.New("no process found")
}
func (o Fake) PidExists(pid int) (bool, error) {
_, found := o.PidTable[pid]
return found, nil
}