...

Source file src/github.com/redhat-developer/odo/pkg/testingutil/system/fake.go

Documentation: github.com/redhat-developer/odo/pkg/testingutil/system

     1  package system
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/mitchellh/go-ps"
     7  )
     8  
     9  type Fake struct {
    10  	ProcessId int
    11  	ParentId  int
    12  	// PidTable is a map of pid => executable name of existing processes
    13  	PidTable map[int]string
    14  }
    15  
    16  func (o Fake) Pid() int {
    17  	return o.ProcessId
    18  }
    19  
    20  func (o Fake) PPid() int {
    21  	return o.ParentId
    22  }
    23  
    24  func (o Fake) Executable() string {
    25  	return o.PidTable[o.ProcessId]
    26  }
    27  
    28  var _ System = Fake{}
    29  
    30  func (o Fake) FindProcess(pid int) (ps.Process, error) {
    31  	if _, found := o.PidTable[pid]; found {
    32  		o.ProcessId = pid
    33  		return o, nil
    34  	}
    35  	return nil, errors.New("no process found")
    36  }
    37  
    38  func (o Fake) PidExists(pid int) (bool, error) {
    39  	_, found := o.PidTable[pid]
    40  	return found, nil
    41  }
    42  

View as plain text