test_cmd_runner

package
v0.0.0-...-86ffc8e Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TestModeEnvVar       = "GO_TEST_MODE"
	CallbackTestMode     = "CALLBACK"
	CallbackFunctionName = "GO_CALLBACK_FUNCTION_NAME"
)

Functions

func RegisterCallback

func RegisterCallback(fn func(cmd string, args ...string) int)

Call this method to register your callback function from your init() method. This is required before creating a TestRunner that uses your function.

func TestMain

func TestMain(m *testing.M)

Types

type TestRunner

type TestRunner struct {
	// contains filtered or unexported fields
}

func NewTestRunner

func NewTestRunner(callback func(cmd string, args ...string) (exitCode int)) (*TestRunner, error)

TestRunner makes it easy to mock out shell commands. It will start a new program that calls into the callback function supplied when creating TestRunner.

To use TestRunner from your test, you must do the following:

  1. In your test file's init() method call RegisterCallback with the same callback function you passed into TestRunner
  2. Copy the TestMain below and insert it into your test file: func TestMain(m *testing.M) { cmd_runner.TestMain(m) }

func NewTestRunnerFailOnErr

func NewTestRunnerFailOnErr(t *testing.T, callback func(cmd string, args ...string) int) *TestRunner

func (*TestRunner) CombinedOutput

func (runner *TestRunner) CombinedOutput(cmd string, args ...string) (string, error)

Jump to

Keyboard shortcuts

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