Documentation
¶
Overview ¶
Package process provides cross-platform process detection utilities.
Index ¶
- func IsProcessRunningWith(ctx context.Context, pattern string, lister ProcessLister) (bool, error)
- func KillProcess(ctx context.Context, pattern string) error
- func KillProcessWith(ctx context.Context, pattern string, lister ProcessLister, ...) error
- type ProcessKiller
- type ProcessKillerMock
- type ProcessLister
- type ProcessListerMock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsProcessRunningWith ¶
IsProcessRunningWith checks if a process is running using the provided lister.
func KillProcess ¶
KillProcess kills all processes matching the given pattern. The pattern is matched against the full command line of the process.
func KillProcessWith ¶
func KillProcessWith(ctx context.Context, pattern string, lister ProcessLister, killer ProcessKiller) error
KillProcessWith kills processes using the provided lister and killer.
Types ¶
type ProcessKiller ¶
ProcessKiller provides an interface for killing processes.
type ProcessKillerMock ¶
type ProcessKillerMock struct {
// KillByPatternFunc mocks the KillByPattern method.
KillByPatternFunc func(ctx context.Context, pattern string) error
// contains filtered or unexported fields
}
ProcessKillerMock is a mock implementation of ProcessKiller.
func TestSomethingThatUsesProcessKiller(t *testing.T) {
// make and configure a mocked ProcessKiller
mockedProcessKiller := &ProcessKillerMock{
KillByPatternFunc: func(ctx context.Context, pattern string) error {
panic("mock out the KillByPattern method")
},
}
// use mockedProcessKiller in code that requires ProcessKiller
// and then make assertions.
}
func (*ProcessKillerMock) KillByPattern ¶
func (mock *ProcessKillerMock) KillByPattern(ctx context.Context, pattern string) error
KillByPattern calls KillByPatternFunc.
func (*ProcessKillerMock) KillByPatternCalls ¶
func (mock *ProcessKillerMock) KillByPatternCalls() []struct { Ctx context.Context Pattern string }
KillByPatternCalls gets all the calls that were made to KillByPattern. Check the length with:
len(mockedProcessKiller.KillByPatternCalls())
type ProcessLister ¶
ProcessLister provides an interface for listing processes.
type ProcessListerMock ¶
type ProcessListerMock struct {
// GetProcessListFunc mocks the GetProcessList method.
GetProcessListFunc func(ctx context.Context) ([]string, error)
// contains filtered or unexported fields
}
ProcessListerMock is a mock implementation of ProcessLister.
func TestSomethingThatUsesProcessLister(t *testing.T) {
// make and configure a mocked ProcessLister
mockedProcessLister := &ProcessListerMock{
GetProcessListFunc: func(ctx context.Context) ([]string, error) {
panic("mock out the GetProcessList method")
},
}
// use mockedProcessLister in code that requires ProcessLister
// and then make assertions.
}
func (*ProcessListerMock) GetProcessList ¶
func (mock *ProcessListerMock) GetProcessList(ctx context.Context) ([]string, error)
GetProcessList calls GetProcessListFunc.
func (*ProcessListerMock) GetProcessListCalls ¶
func (mock *ProcessListerMock) GetProcessListCalls() []struct { Ctx context.Context }
GetProcessListCalls gets all the calls that were made to GetProcessList. Check the length with:
len(mockedProcessLister.GetProcessListCalls())