Documentation ¶
Overview ¶
Package testio implements various io utility types. Included are BrokenWriter, which fails after writing a certain number of bytes; a BufCloser, which wraps a bytes.Buffer in a Close method; a BrokenReadWriter, which fails after writing a certain number of bytes and/or reading a certain number of bytes; a LoggingBuffer that logs all reads and writes; and a BufferConn, that is designed to simulate net.Conn.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BrokenCloser ¶
type BrokenCloser struct {
// contains filtered or unexported fields
}
BrokenCloser is a BufCloser that fails to close.
func NewBrokenCloser ¶
func NewBrokenCloser(buf []byte) *BrokenCloser
NewBrokenCloser creates and initializes a new BrokenCloser using buf as its initial contents. It is intended to prepare a BrokenCloser to read existing data. It can also be used to size the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.
func NewBrokenCloserString ¶
func NewBrokenCloserString(s string) *BrokenCloser
NewBrokenCloserString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string.
func (*BrokenCloser) Bytes ¶
func (buf *BrokenCloser) Bytes() []byte
Bytes returns the contents of the buffer as a byte slice.
func (*BrokenCloser) Close ¶
func (buf *BrokenCloser) Close() error
Close is a stub function to satisfy the io.Closer interface.
type BrokenReadWriter ¶
type BrokenReadWriter struct {
// contains filtered or unexported fields
}
BrokenReadWriter implements a broken reader and writer, backed by a bytes.Buffer.
func NewBrokenReadWriter ¶
func NewBrokenReadWriter(wlimit, rlimit int) *BrokenReadWriter
NewBrokenReadWriter initialises a new BrokerReadWriter with an empty reader and the specified limits.
func (*BrokenReadWriter) Extend ¶
func (brw *BrokenReadWriter) Extend(w, r int)
Extend increases the BrokenReadWriter limit.
func (*BrokenReadWriter) Read ¶
func (brw *BrokenReadWriter) Read(p []byte) (int, error)
Read satisfies the Reader interface.
func (*BrokenReadWriter) Reset ¶
func (brw *BrokenReadWriter) Reset()
Reset clears the internal buffer. It retains its original limit.
type BrokenWriter ¶
type BrokenWriter struct {
// contains filtered or unexported fields
}
BrokenWriter implements an io.Writer that fails after a certain number of bytes. This can be used to simulate a network connection that breaks during write or a file on a filesystem that becomes full, for example. A BrokenWriter doesn't actually store any data.
func NewBrokenWriter ¶
func NewBrokenWriter(limit int) *BrokenWriter
NewBrokenWriter creates a new BrokenWriter that can store only limit bytes.
func (*BrokenWriter) Close ¶
func (w *BrokenWriter) Close() error
Close is provided to satisfy the Closer interface.
func (*BrokenWriter) Extend ¶
func (w *BrokenWriter) Extend(n int)
Extend increases the byte limit to allow more data to be written.
func (*BrokenWriter) Reset ¶
func (w *BrokenWriter) Reset()
Reset clears the limit and bytes in the BrokenWriter. Extend needs to be called to allow data to be written.
type BufCloser ¶
type BufCloser struct {
// contains filtered or unexported fields
}
BufCloser is a buffer wrapped with a Close method.
func NewBufCloser ¶
NewBufCloser creates and initializes a new BufCloser using buf as its initial contents. It is intended to prepare a BufCloser to read existing data. It can also be used to size the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.
func NewBufCloserString ¶
NewBufCloserString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string.
type BufferConn ¶
type BufferConn struct {
// contains filtered or unexported fields
}
BufferConn is a type that can be used to simulate network connections between a "client" (the code that uses the BufferConn) and some simulated "peer". Writes go to a "client" buffer, which is used to record the data sent by the caller, which may be read with ReadPeer. The peer's responses may be simulated by calling WritePeer; when the client reads from the BufferConn, they will see this data.
func NewBufferConn ¶
func NewBufferConn() *BufferConn
NewBufferConn initialises a new simulated network connection.
func (*BufferConn) Close ¶
func (bc *BufferConn) Close() error
Close is a dummy operation that allows the BufferConn to be used as an io.Closer.
func (*BufferConn) Read ¶
func (bc *BufferConn) Read(p []byte) (int, error)
Read reads from the peer buffer.
func (*BufferConn) ReadClient ¶
func (bc *BufferConn) ReadClient(p []byte) (int, error)
ReadClient reads data from the client buffer.
type LoggingBuffer ¶
type LoggingBuffer struct {
// contains filtered or unexported fields
}
A LoggingBuffer is an io.ReadWriter that prints the hex value of the data for all reads and writes.
func NewLoggingBuffer ¶
func NewLoggingBuffer(rw io.ReadWriter) *LoggingBuffer
NewLoggingBuffer creates a logging buffer from an existing io.ReadWriter. By default, it will log to standard error.
func (*LoggingBuffer) LogTo ¶
func (lb *LoggingBuffer) LogTo(w io.Writer)
LogTo sets the io.Writer that the buffer will write logs to.
func (*LoggingBuffer) Read ¶
func (lb *LoggingBuffer) Read(p []byte) (int, error)
Read reads the data from the logging buffer and writes the data to the logging writer.
func (*LoggingBuffer) SetName ¶
func (lb *LoggingBuffer) SetName(name string)
SetName gives a name to the logging buffer to help distinguish output from this buffer.
type SilentBrokenWriter ¶
type SilentBrokenWriter struct {
// contains filtered or unexported fields
}
SilentBrokenWriter implements an io.Writer that fails after a certain number of bytes. However, this failure is silent: it just reports fewer bytes written than p. It doesn't actually store any data, and is used to verify that io.Writer implementations properly return errors on short writes.
func NewSilentBrokenWriter ¶
func NewSilentBrokenWriter(limit int) *SilentBrokenWriter
NewSilentBrokenWriter creates a new SilentBrokenWriter that can store only limit bytes.
func (*SilentBrokenWriter) Close ¶
func (w *SilentBrokenWriter) Close() error
Close is provided to satisfy the Closer interface.
func (*SilentBrokenWriter) Extend ¶
func (w *SilentBrokenWriter) Extend(n int)
Extend increases the byte limit to allow more data to be written.
func (*SilentBrokenWriter) Reset ¶
func (w *SilentBrokenWriter) Reset()
Reset clears the limit and bytes in the SilentBrokenWriter. Extend needs to be called to allow data to be written.