mockio

package
v0.0.0-...-c936f35 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Readable

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

func Stdin() *Readable

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

func (*Readable) Read

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

Read satisfies the io.Reader interface.

func (*Readable) ShouldError

func (r *Readable) ShouldError(e error)

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

func (*Readable) Write

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

Write satisfies the io.Writer interface.

func (*Readable) WriteString

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

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

type Writable

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

func Stdout() *Writable

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

func (*Writable) ReadNow

func (w *Writable) ReadNow() string

ReadNow clears the buffer and returns its previous contents.

func (*Writable) ReadUntil

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

func (w *Writable) ShouldError(e error)

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

func (*Writable) WaitForWrite

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

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

func (*Writable) Write

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

Write satisfies the io.Writer interface.

Jump to

Keyboard shortcuts

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