Documentation ¶
Overview ¶
Package command provides system command execution.
Index ¶
Constants ¶
const ( // TimeoutOutput specifies the command execution output in the // event of an execution timeout. TimeoutOutput string = "Execution timed out\n" // OKExitStatus specifies the command execution exit status // that indicates a success, A-OK. OKExitStatus int = 0 // TimeoutExitStatus specifies the command execution exit // status in the event of an execution timeout. TimeoutExitStatus int = 2 // FallbackExitStatus specifies the command execution exit // status used when golang is unable to determine the exit // status. FallbackExitStatus int = 3 )
Variables ¶
This section is empty.
Functions ¶
func KillProcess ¶
KillProcess kills the command process and any child processes
func SetProcessGroup ¶
SetProcessGroup sets the process group of the command process
Types ¶
type ExecutionRequest ¶
type ExecutionRequest struct { // Command is the command to be executed. Command string // Env ... Env []string // Input to provide the command via STDIN. Input string // Execution timeout in seconds, will be set to a default if // not specified. Timeout int // Name is the name of the resource that is invoking the execution. Name string // InProgress is a map of checks that are still in execution, this is // necessary for a check or hook to escape zombie processes. InProgress map[string]*types.CheckConfig // InProgressMu is the mutex for the InProgress map. InProgressMu *sync.Mutex }
ExecutionRequest provides information about a system command execution, somewhat of an abstraction intended to be used for Sensu check, mutator, and handler execution.
func FakeCommand ¶
func FakeCommand(command string, args ...string) ExecutionRequest
FakeCommand takes a command and (optionally) command args and will execute the TestHelperProcess test within the package FakeCommand is called from.
func (*ExecutionRequest) Execute ¶
func (e *ExecutionRequest) Execute(ctx context.Context, execution ExecutionRequest) (*ExecutionResponse, error)
Execute executes a system command (fork/exec) with a timeout, optionally writing to STDIN, capturing its combined output (STDOUT/ERR) and exit status.
type ExecutionResponse ¶
type ExecutionResponse struct { // Combined command execution STDOUT/ERR. Output string // Command execution exit status. Status int // Duration provides command execution time in seconds. Duration float64 }
ExecutionResponse provides the response information of an ExecutionRequest.
func FixtureExecutionResponse ¶
func FixtureExecutionResponse(status int, output string) *ExecutionResponse
FixtureExecutionResponse returns an Execution for use in testing
type Executor ¶
type Executor interface {
Execute(context.Context, ExecutionRequest) (*ExecutionResponse, error)
}
Executor ...