Documentation ¶
Overview ¶
Package filetest provides utility functions that can be used during unit testing. Any resource created by the package during a test is cleaned up automatically when the test is done.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateDir ¶
CreateDir creates a temporary directory. The directory is deleted after the test is done running.
func CreateFile ¶
CreateFile creates a temporary file with the content specified used during the test. The file is closed and deleted after the test is done running.
func OverrideStdin ¶
OverrideStdin overrides os.Stdin with the specified file and restores it after the test.
Types ¶
type StubReader ¶
StubReader implements the io.ReadCloser interface. It is used during tests to return the content of its internal buffer, or to return an error as needed.
func NewStubReader ¶
func NewStubReader(buffer []byte, err error) *StubReader
NewStubReader returns a new StubReader object that reads from the buffer specified. If err is not nil, it will return an error on the first read. If the end of the buffer is reached, it will return an io.EOF error.
func (*StubReader) Close ¶
func (r *StubReader) Close() error
Close implements the io.Closer interface.
type StubWriter ¶
StubWriter implements the io.Writer interface. It is used during tests to examine the content of the data written, and to return fake errors as needed.
func NewStubWriter ¶
func NewStubWriter(err error) *StubWriter
NewStubWriter returns a new StubWriter.
func (*StubWriter) Close ¶
func (w *StubWriter) Close() error
Close implements the io.Closer interface.