top

A wrapper around the os/exec package that supports timeouts and testing.

Example usage:

Simple command with argument: err := Run(&Command{

Name: "touch",
Args: []string{file},

})

More complicated example: output := bytes.Buffer{} err := Run(&Command{

Name: "make",
Args: []string{"all"},
// Set environment:
Env: []string{fmt.Sprintf("GOPATH=%s", projectGoPath)},
// Set working directory:
Dir: projectDir,
// Capture output:
CombinedOutput: &output,
// Set a timeout:
Timeout: 10*time.Minute,

})

Inject a Run function for testing: var actualCommand *Command SetRunForTesting(func(command *Command) error {

actualCommand = command
return nil

}) defer SetRunForTesting(DefaultRun) TestCodeCallingRun() expect.Equal(t, "touch", actualCommand.Name) expect.Equal(t, 1, len(actualCommand.Args)) expect.Equal(t, file, actualCommand.Args[0])

Types and functions to help with testing code that uses exec.Run.

Imports 2 package(s)

  1. go.skia.org/infra/go/sklog
  2. go.skia.org/infra/go/util

Test imports 3 package(s)

  1. github.com/stretchr/testify/assert
  2. go.skia.org/infra/go/testutils
  3. github.com/stretchr/testify/require