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.

Imported by 37 package(s)

  1. github.com/google/skia-buildbot/go/buildbucket/generate
  2. github.com/google/skia-buildbot/go/buildskia
  3. github.com/google/skia-buildbot/go/cq/generate
  4. github.com/google/skia-buildbot/go/exec/testutils
  5. github.com/google/skia-buildbot/go/git
  6. github.com/google/skia-buildbot/go/git/gitinfo
  7. github.com/google/skia-buildbot/go/git/testutils
  8. github.com/google/skia-buildbot/go/gitinfo
  9. github.com/google/skia-buildbot/go/gitrepo
  10. github.com/google/skia-buildbot/go/isolate
  11. github.com/google/skia-buildbot/go/packages
  12. github.com/google/skia-buildbot/go/swarming
  13. github.com/jcgregorio/piccolo/piccolo
  14. go.skia.org/infra/go/buildbucket/generate
  15. go.skia.org/infra/go/buildskia
  16. go.skia.org/infra/go/cq/generate
  17. go.skia.org/infra/go/exec/testutils
  18. go.skia.org/infra/go/git
  19. go.skia.org/infra/go/git/gitinfo
  20. go.skia.org/infra/go/git/testutils
  21. go.skia.org/infra/go/gitinfo
  22. go.skia.org/infra/go/gitrepo
  23. go.skia.org/infra/go/isolate
  24. go.skia.org/infra/go/packages
  25. go.skia.org/infra/go/swarming
  26. go.skia.org/infra/scripts/roll_recipe_deps
  27. skia.googlesource.com/buildbot.git/go/buildbucket/generate
  28. skia.googlesource.com/buildbot.git/go/buildskia
  29. skia.googlesource.com/buildbot.git/go/cq/generate
  30. skia.googlesource.com/buildbot.git/go/exec/testutils
  31. skia.googlesource.com/buildbot.git/go/git
  32. skia.googlesource.com/buildbot.git/go/git/gitinfo
  33. skia.googlesource.com/buildbot.git/go/git/testutils
  34. skia.googlesource.com/buildbot.git/go/isolate
  35. skia.googlesource.com/buildbot.git/go/packages
  36. skia.googlesource.com/buildbot.git/go/swarming
  37. skia.googlesource.com/buildbot.git/scripts/roll_recipe_deps

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. github.com/stretchr/testify/require
  3. go.skia.org/infra/go/testutils