Documentation
¶
Overview ¶
Package stdio provides utilities for mocking os.Stdin, os.Stdout and os.Stderr for unit testing purposes
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrAlreadyCaptured = errors.New("already captured")
)
View Source
var ( // StderrTempPattern is the pattern used with calling os.CreateTemp to make // the new temp file during os.Stderr Capture operations StderrTempPattern = "corelibs-mock-stdio.*.err" )
View Source
var ( // StdoutTempPattern is the pattern used with calling os.CreateTemp to make // the new temp file during os.Stdout Capture operations StdoutTempPattern = "corelibs-mock-stdio.*.out" )
Functions ¶
This section is empty.
Types ¶
type Stdio ¶
type Stdio interface {
// Capture will replace the os file handle with a faked one that writes data
// to a temporary file
Capture() (err error)
// Restore will replace the faked os file handle with the original one
// captured
Restore()
// Data returns the contents of the temporary file
Data() (data []byte)
// Reader returns the *os.File instance for read operations
Reader() (r *os.File)
// Writer returns the *os.File instance for read operations
Writer() (w *os.File)
// Reset will Restore and then Capture the os file handle again
Reset() (err error)
}
func NewStderr ¶
func NewStderr() (s Stdio)
NewStderr creates a new Stdio instance that will Capture os.Stderr
Click to show internal directories.
Click to hide internal directories.