exec

package
v0.0.0-...-9eda336 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package exec is intended to be a drop-in replacement for "os/exec" which can be mocked.

See the docs in `go.chromium.org/luci/common/exec/execmock` for information on how mocking exec works.

NOTE: `Command` now takes a context; this context will only be used for the purpose of mocking, but still allows you to make a Command which is not bound to the lifetime of the context (i.e. will not be automatically killed when the context is Done()).

Index

Constants

This section is empty.

Variables

View Source
var ErrUseConstructor = errors.New("you must use Command or CommandContext to create a usable Cmd")

ErrUseConstructor is returned from methods of Cmd if the Cmd struct was created without using Command or CommandContext.

View Source
var LookPath = exec.LookPath

LookPath searches for an executable named file in the directories named by the PATH environment variable. If file contains a slash, it is tried directly and the PATH is not consulted. The result may be an absolute path or a path relative to the current directory.

This is an alias of `"os/exec".LookPath`.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	// We embed the *Cmd without a field name so that users can drop in our struct
	// where they previously had an *"os/exec".Cmd with minimal code changes.
	*exec.Cmd
	// contains filtered or unexported fields
}

Cmd behaves like an "os/exec".Cmd, except that it can be mocked using the "go.chromium.org/luci/common/exec/execmock" package.

Must be created with Command or CommandContext.

Mocking this Cmd allows the test program to substitute this Cmd invocation transparently with another, customized, subprocess.

func Command

func Command(ctx context.Context, name string, arg ...string) *Cmd

Command behaves like "os/exec".Command, except that it can be mocked via the "go.chromium.org/luci/common/exec/execmock" package.

Note that although this takes a Context, it does not bind the lifetime of the returned Cmd to `ctx`.

func CommandContext

func CommandContext(ctx context.Context, name string, arg ...string) *Cmd

CommandContext behaves like "os/exec".CommandContext, except that it can be mocked via the "go.chromium.org/luci/common/exec/execmock" package.

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput() ([]byte, error)

CombinedOutput operates the same as "os/exec".Cmd.CombinedOutput.

func (*Cmd) Output

func (c *Cmd) Output() ([]byte, error)

Output operates the same as "os/exec".Cmd.Output.

func (*Cmd) Run

func (c *Cmd) Run() error

Run operates the same as "os/exec".Cmd.Run.

func (*Cmd) Start

func (c *Cmd) Start() error

Start operates the same as "os/exec".Cmd.Start.

func (*Cmd) StderrPipe

func (c *Cmd) StderrPipe() (io.ReadCloser, error)

StderrPipe operates the same as "os/exec".Cmd.StderrPipe.

func (*Cmd) StdoutPipe

func (c *Cmd) StdoutPipe() (io.ReadCloser, error)

StdoutPipe operates the same as "os/exec".Cmd.StdoutPipe.

func (*Cmd) Wait

func (c *Cmd) Wait() error

Wait operates the same as "os/exec".Cmd.Wait.

type Error

type Error = exec.Error

Error is returned by LookPath when it fails to classify a file as an executable.

This is an alias of `"os/exec".Error`.

type ExitError

type ExitError = exec.ExitError

An ExitError reports an unsuccessful exit by a command.

This is an alias of `"os/exec".ExitError`.

Directories

Path Synopsis
Package execmock allows mocking exec commands using the go.chromium.org/luci/common/exec ("luci exec") library, which is nearly a drop-in replacement for the "os/exec" stdlib library.
Package execmock allows mocking exec commands using the go.chromium.org/luci/common/exec ("luci exec") library, which is nearly a drop-in replacement for the "os/exec" stdlib library.
internal
execmockctx
Package execmockctx provides the minimum interface that the `go.chromium.org/luci/common/exec` library needs to hook into the mocking system provided by `go.chromium.org/luci/common/exec/execmock` without needing to actually link the execmock code (including it's registration of the Simple runner, and the implementation of the http test server) into non-test binaries.
Package execmockctx provides the minimum interface that the `go.chromium.org/luci/common/exec` library needs to hook into the mocking system provided by `go.chromium.org/luci/common/exec/execmock` without needing to actually link the execmock code (including it's registration of the Simple runner, and the implementation of the http test server) into non-test binaries.
execmockserver
Package execmockserver implements the "net/rpc" based client/server pair which is used by execmock to communicate to/from mock subprocesses.
Package execmockserver implements the "net/rpc" based client/server pair which is used by execmock to communicate to/from mock subprocesses.

Jump to

Keyboard shortcuts

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