execfactory

package module
v0.0.0-...-0070306 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: MIT Imports: 8 Imported by: 0

README

execfactory

Build Status Coverage Status

A small Go package to allow for mocking out shell commands in os/exec

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PipeCommands

func PipeCommands(r1 Cmder, r2 Cmder) string

PipeCommands will pipe two commands together and return the output

Types

type Cmder

type Cmder interface {
	Run() error
	Start() error
	String() string
	CombinedOutput() ([]byte, error)
	Output() ([]byte, error)
	SimpleOutput() ([]byte, int)
	StdinPipe() (io.WriteCloser, error)
	StderrPipe() (io.ReadCloser, error)
	StdoutPipe() (io.ReadCloser, error)
	Wait() error
	// contains filtered or unexported methods
}

Cmder interface wraps the os/exec Cmd struct

type Creator

type Creator interface {
	Command(name string, arg ...string) Cmder
	CommandContext(ctx context.Context, name string, arg ...string) Cmder
}

Creator is the interface used to create either a mock or real os/exec Cmd

func NewOSCreator

func NewOSCreator() Creator

NewOSCreator instantiates a real os/exec factory

type MockCreator

type MockCreator interface {
	Creator
}

MockCreator is the interface used to create a mock os/exec Cmd

func NewMockCreator

func NewMockCreator(instances []MockInstance) MockCreator

NewMockCreator instantiates a mock os/exec factory

type MockInstance

type MockInstance struct {
	RunErr               error
	StartErr             error
	CombinedOutputVal    []byte
	CombinedOutputErr    error
	OutputVal            []byte
	OutputErr            error
	SimpleOutputOut      []byte
	SimpleOutputExitCode int
	StdinPipeVal         io.WriteCloser
	StdinPipeErr         error
	StderrPipeVal        io.ReadCloser
	StderrPipeErr        error
	StdoutPipeVal        io.ReadCloser
	StdoutPipeErr        error
	WaitErr              error
}

MockInstance defines the returned values of the mock Cmd method calls

Jump to

Keyboard shortcuts

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