barista.run: barista.run/testing/mockio Index | Files

package mockio

import "barista.run/testing/mockio"

Package mockio provides infinite streams that can be used for testing stdin/stdout.

Index

Package Files

mockio.go

type Readable Uses

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

Readable is an infinite stream that satisfies io.Reader and io.Writer Reads block until something is written to the stream, which mimics stdin.

func Stdin Uses

func Stdin() *Readable

Stdin returns a Readable that can be used in place of stdin for testing.

func (*Readable) Read Uses

func (r *Readable) Read(out []byte) (n int, e error)

Read satisfies the io.Reader interface.

func (*Readable) ShouldError Uses

func (r *Readable) ShouldError(e error)

ShouldError sets the stream to return an error on the next read.

func (*Readable) Write Uses

func (r *Readable) Write(out []byte) (n int, e error)

Write satisfies the io.Writer interface.

func (*Readable) WriteString Uses

func (r *Readable) WriteString(s string) (n int, e error)

WriteString proxies directly to the byte buffer but adds a signal.

type Writable Uses

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

Writable is an infinite stream that satisfies io.Writer, and adds methods to get portions of the output written to it.

func Stdout Uses

func Stdout() *Writable

Stdout returns a Writable that can be used for making assertions against what was written to stdout.

func (*Writable) ReadNow Uses

func (w *Writable) ReadNow() string

ReadNow clears the buffer and returns its previous contents.

func (*Writable) ReadUntil Uses

func (w *Writable) ReadUntil(delim byte, timeout time.Duration) (string, error)

ReadUntil reads up to the first occurrence of the given character, or until the timeout expires, whichever comes first.

func (*Writable) ShouldError Uses

func (w *Writable) ShouldError(e error)

ShouldError sets the stream to return an error on the next write.

func (*Writable) WaitForWrite Uses

func (w *Writable) WaitForWrite(timeout time.Duration) bool

WaitForWrite waits until the timeout for a write to this stream.

func (*Writable) Write Uses

func (w *Writable) Write(out []byte) (n int, e error)

Write satisfies the io.Writer interface.

Package mockio imports 4 packages (graph). Updated 2018-09-03. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).