Documentation
¶
Index ¶
- Constants
- func EnsureProcessTree(t *testing.T, rootP process.ProcessTreeItem, expectedSize int, ...)
- func GetTestToolDir(exeName string) (string, error)
- func ServeHttp(lifetimeCtx context.Context, routes []RouteSpec) string
- func ServeHttpFrom(lifetimeCtx context.Context, address string, port int32, routes []RouteSpec) string
- type AutoExecution
- type ProcessExecution
- type ProcessSearchCriteria
- type ProcessSearchCriteriaCond
- type ResponseSpec
- type RouteSpec
- type TestHttpEndpoint
- func (e *TestHttpEndpoint) AddressAndPort() (string, int32, error)
- func (e *TestHttpEndpoint) SetHealthyResponseObserver(observer func(*http.Request))
- func (e *TestHttpEndpoint) SetOutcome(outcome apiv1.HealthProbeOutcome)
- func (e *TestHttpEndpoint) SetUnhealthyResponseObserver(observer func(*http.Request))
- func (e *TestHttpEndpoint) Url() string
- type TestProcessExecutor
- func (e *TestProcessExecutor) ClearHistory()
- func (e *TestProcessExecutor) Close() error
- func (e *TestProcessExecutor) Dispose()
- func (e *TestProcessExecutor) FindAll(command []string, lastArg string, cond ProcessSearchCriteriaCond) []*ProcessExecution
- func (e *TestProcessExecutor) FindByPid(pid process.Pid_t) (*ProcessExecution, bool)
- func (e *TestProcessExecutor) InstallAutoExecution(autoExecution AutoExecution)
- func (e *TestProcessExecutor) RemoveAutoExecution(sc ProcessSearchCriteria)
- func (e *TestProcessExecutor) SimulateProcessExit(t *testing.T, pid process.Pid_t, exitCode int32)
- func (e *TestProcessExecutor) StartAndForget(cmd *exec.Cmd, _ process.ProcessCreationFlag) (process.Pid_t, time.Time, error)
- func (e *TestProcessExecutor) StartProcess(ctx context.Context, cmd *exec.Cmd, handler process.ProcessExitHandler, ...) (process.Pid_t, time.Time, func(), error)
- func (e *TestProcessExecutor) StopProcess(pid process.Pid_t, processStartTime time.Time) error
Constants ¶
const ( NotFound = -1 KilledProcessExitCode = 137 // 128 + SIGKILL (9) )
const TestHttpEndpointPath = "/healthz"
Variables ¶
This section is empty.
Functions ¶
func EnsureProcessTree ¶
func GetTestToolDir ¶
Returns the folder containing desired test tool (executable).
Types ¶
type AutoExecution ¶
type AutoExecution struct {
// The criteria that needs to be matched for the command to be executed.
// There is no safeguard against multiple commands matching the criteria.
Condition ProcessSearchCriteria
// The RunCommand function is called after the process is "running".
// It can write to command stdout and stderr. The return value is an exit code for the command.
// The function should be checking pe.Signal channel to see if any signals were sent to the process.
// The test convention is that execution should stop when SIGTERM is received.
RunCommand func(pe *ProcessExecution) int32
// If not nil, this is the error that will be returned by the Executor from StartProcess() call.
// RunCommand will not be called in this case.
StartupError func(*ProcessExecution) error
// If not nil, the process will fail to stop with the specified error.
StopError func(*ProcessExecution) error
// AsynchronousStartupDelay is used to simulate asynchronous process startup.
// If set to a non-zero value, the process startup will be delayed by the specified duration.
AsynchronousStartupDelay time.Duration
}
AutoExecution structure is used by clients to automatically and asynchronously complete an execution of a command that matches certain criteria.
type ProcessExecution ¶
type ProcessExecution struct {
PID process.Pid_t
Cmd *exec.Cmd
StartWaitingCalled bool
StartedAt time.Time
EndedAt time.Time
ExitHandler process.ProcessExitHandler
ExitCode int32
ExecutionEnded chan struct{}
Signal chan syscall.Signal // Channel to send simulated signals to the process
Executor *TestProcessExecutor // The reference to the executor that created this process execution.
// contains filtered or unexported fields
}
func WaitForCommand ¶
func WaitForCommand( executor *TestProcessExecutor, ctx context.Context, command []string, lastArg string, cond func(*ProcessExecution) bool, ) (*ProcessExecution, error)
Waits for an execution of a specific command to be issued. The command is identified by path to the executable and a subset of its arguments (the first N arguments). If lastArg parameter is not empty, it is matched against the last argument of the command. Last parameter is a function that is called to verify that the command is the one we are waiting for.
func (*ProcessExecution) Finished ¶
func (pe *ProcessExecution) Finished() bool
func (*ProcessExecution) Running ¶
func (pe *ProcessExecution) Running() bool
type ProcessSearchCriteria ¶
type ProcessSearchCriteria struct {
Command []string // The name/path of the executable and first N arguments, if any.
LastArg string // The last argument of the command that needs to match. Optional.
Cond ProcessSearchCriteriaCond // Special condition to match the command. Optional.
}
func (*ProcessSearchCriteria) Equals ¶
func (sc *ProcessSearchCriteria) Equals(other *ProcessSearchCriteria) bool
func (*ProcessSearchCriteria) Matches ¶
func (sc *ProcessSearchCriteria) Matches(pe *ProcessExecution) bool
func (*ProcessSearchCriteria) MatchesCmd ¶ added in v0.22.2
func (sc *ProcessSearchCriteria) MatchesCmd(cmd *exec.Cmd) bool
type ProcessSearchCriteriaCond ¶
type ProcessSearchCriteriaCond func(pe *ProcessExecution) bool
type ResponseSpec ¶
type ResponseSpec struct {
// StatusCode is the HTTP status code to return.
StatusCode int
// Body is the response body to return. If empty, no body will be returned.
Body []byte
// Active is set to true if the response should be used for the next request.
Active *atomic.Bool
// A function to call when the response is used.
Observer func(*http.Request)
}
ResponseSpec describes how HTTP test server should reply to a single request.
type RouteSpec ¶
type RouteSpec struct {
// Pattern (see net/http.ServeMux) to match the request path.
Pattern string
// Set of response specs to use for this route.
// The first response that is "active" will be used.
// if there is no active response spec, the request will return 404.
Responses []ResponseSpec
}
The route spec describes how the HTTP test server should route and handle requests.
type TestHttpEndpoint ¶
type TestHttpEndpoint struct {
// contains filtered or unexported fields
}
And endpoint for testing HTTP health probes. It returns "success" or "failure" response, depending on the configuration. The configuration can be changed at run time; initially the endpoint responds with "unhealthy" response.
func NewTestHttpEndpoint ¶
func NewTestHttpEndpoint(lifetimeCtx context.Context) *TestHttpEndpoint
func NewTestHttpEndpointWithAddressAndPort ¶
func NewTestHttpEndpointWithAddressAndPort(lifetimeCtx context.Context, address string, port int32) *TestHttpEndpoint
func (*TestHttpEndpoint) AddressAndPort ¶
func (e *TestHttpEndpoint) AddressAndPort() (string, int32, error)
func (*TestHttpEndpoint) SetHealthyResponseObserver ¶
func (e *TestHttpEndpoint) SetHealthyResponseObserver(observer func(*http.Request))
func (*TestHttpEndpoint) SetOutcome ¶
func (e *TestHttpEndpoint) SetOutcome(outcome apiv1.HealthProbeOutcome)
func (*TestHttpEndpoint) SetUnhealthyResponseObserver ¶
func (e *TestHttpEndpoint) SetUnhealthyResponseObserver(observer func(*http.Request))
func (*TestHttpEndpoint) Url ¶
func (e *TestHttpEndpoint) Url() string
type TestProcessExecutor ¶
type TestProcessExecutor struct {
Executions []*ProcessExecution
AutoExecutions []AutoExecution
// contains filtered or unexported fields
}
func NewTestProcessExecutor ¶
func NewTestProcessExecutor(lifetimeCtx context.Context) *TestProcessExecutor
func (*TestProcessExecutor) ClearHistory ¶
func (e *TestProcessExecutor) ClearHistory()
Clears all execution history
func (*TestProcessExecutor) Close ¶
func (e *TestProcessExecutor) Close() error
func (*TestProcessExecutor) Dispose ¶
func (e *TestProcessExecutor) Dispose()
func (*TestProcessExecutor) FindAll ¶
func (e *TestProcessExecutor) FindAll( command []string, lastArg string, cond ProcessSearchCriteriaCond, ) []*ProcessExecution
Finds all executions of a specific command. The command is identified by path to the executable and a subset of its arguments (the first N arguments). If lastArg parameter is not empty, it is matched against the last argument of the command. Last parameter is a function that is called to verify that the command is the one we are waiting for.
func (*TestProcessExecutor) FindByPid ¶
func (e *TestProcessExecutor) FindByPid(pid process.Pid_t) (*ProcessExecution, bool)
func (*TestProcessExecutor) InstallAutoExecution ¶
func (e *TestProcessExecutor) InstallAutoExecution(autoExecution AutoExecution)
func (*TestProcessExecutor) RemoveAutoExecution ¶
func (e *TestProcessExecutor) RemoveAutoExecution(sc ProcessSearchCriteria)
func (*TestProcessExecutor) SimulateProcessExit ¶
Called by tests to simulate a process exit with specific exit code.
func (*TestProcessExecutor) StartAndForget ¶
func (e *TestProcessExecutor) StartAndForget(cmd *exec.Cmd, _ process.ProcessCreationFlag) (process.Pid_t, time.Time, error)
func (*TestProcessExecutor) StartProcess ¶
func (e *TestProcessExecutor) StartProcess( ctx context.Context, cmd *exec.Cmd, handler process.ProcessExitHandler, _ process.ProcessCreationFlag, ) (process.Pid_t, time.Time, func(), error)
func (*TestProcessExecutor) StopProcess ¶
Called by the controller (via Executor interface)