process

package
v0.1.0-alpha.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package process provides cross-platform process detection utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsProcessRunningWith

func IsProcessRunningWith(ctx context.Context, pattern string, lister ProcessLister) (bool, error)

IsProcessRunningWith checks if a process is running using the provided lister.

func KillProcess

func KillProcess(ctx context.Context, pattern string) error

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

type ProcessKiller interface {
	KillByPattern(ctx context.Context, pattern string) error
}

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

type ProcessLister interface {
	GetProcessList(ctx context.Context) ([]string, error)
}

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())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL