testutils

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTemporaryTrue is an error that implements a Temporary method
	// that always returns true.
	ErrTemporaryTrue tempErr = true

	// ErrTemporaryFalse is an error that implements a Temporary method
	// that always returns false.
	ErrTemporaryFalse tempErr = false
)

Functions

This section is empty.

Types

type MockConn

type MockConn struct {
	// Function to call when Read is called.
	ReadFunc func(i int, b []byte) (int, error)
	// Function to call when Write is called.
	WriteFunc func(i int, b []byte) (int, error)

	// Error to return when Close is called.
	CloseErr error
	// If set, the channel is closed when Close is called.
	CloseChan chan struct{}

	// Local address to return when LocalAddr is called.
	LocalAddress net.Addr
	// Remote address to return when RemoteAddr is called.
	RemoteAddress net.Addr
	// contains filtered or unexported fields
}

MockConn implements a net.Conn that can be used for testing. Deadline methods are no-ops.

func (*MockConn) Close

func (c *MockConn) Close() error

Close implements io.Closer for MockConn.

func (*MockConn) CloseCalls

func (c *MockConn) CloseCalls() int

CloseCalls returns the number of times Close was called.

func (*MockConn) ClosedAt added in v0.0.2

func (c *MockConn) ClosedAt() time.Time

ClosedAt returns the timestamp at which the connection was closed.

func (*MockConn) LocalAddr

func (c *MockConn) LocalAddr() net.Addr

LocalAddr returns the local address of the connection.

func (*MockConn) Read

func (c *MockConn) Read(b []byte) (int, error)

Read implements io.Reader for MockConn.

func (*MockConn) ReadCalls

func (c *MockConn) ReadCalls() int

ReadCalls returns the number of times Read was called.

func (*MockConn) RemoteAddr

func (c *MockConn) RemoteAddr() net.Addr

RemoteAddr returns the remote address of the connection.

func (*MockConn) SetDeadline

func (c *MockConn) SetDeadline(t time.Time) error

SetDeadline is a no-op for MockConn.

func (*MockConn) SetReadDeadline

func (c *MockConn) SetReadDeadline(t time.Time) error

SetReadDeadline is a no-op for MockConn.

func (*MockConn) SetWriteDeadline

func (c *MockConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline is a no-op for MockConn.

func (*MockConn) Write

func (c *MockConn) Write(b []byte) (int, error)

Write implements io.Writer for MockConn.

func (*MockConn) WriteCalls

func (c *MockConn) WriteCalls() int

WriteCalls returns the number of times Write was called.

type MockListener

type MockListener struct {
	// AcceptFunc is the function called whenever Accept is called.
	// The i parameter indicates the 0-based index of the call.
	AcceptFunc func(i int) (net.Conn, error)
	// Error to return when Close is called on the Listener.
	CloseErr error
	// If set, this channel is closed when Close is called.
	CloseChan chan struct{}
	// Address to return when Addr is called on the Listener.
	Address net.Addr
	// contains filtered or unexported fields
}

MockListener is a net.Listener that calls AcceptFunc to return the connection and error.

func (*MockListener) Accept

func (l *MockListener) Accept() (net.Conn, error)

Accept accepts a connection.

func (*MockListener) AcceptCalls

func (l *MockListener) AcceptCalls() int

AcceptCalls returns the number of times Accept was called.

func (*MockListener) Addr

func (l *MockListener) Addr() net.Addr

Addr returns the address the Listener listens on.

func (*MockListener) Close

func (l *MockListener) Close() error

Close closes the Listener.

func (*MockListener) CloseCalls

func (l *MockListener) CloseCalls() int

CloseCalls returns the number of times Close was called.

type MockSSHClient

type MockSSHClient struct {
	// Function to call when Dial is called.
	DialFunc func(i int, network, address string) (net.Conn, error)

	// Error to return when Close is called.
	CloseErr error
	// If set, the channel is closed when Close is called.
	CloseChan chan struct{}
	// contains filtered or unexported fields
}

MockSSHClient implements an SSH client (more specifically, a dialCloser interface as defined in the server package) that can be used for tests.

func (*MockSSHClient) Close

func (c *MockSSHClient) Close() error

Close closes the SSH client.

func (*MockSSHClient) CloseCalls

func (c *MockSSHClient) CloseCalls() int

CloseCalls returns the number of times Close was called.

func (*MockSSHClient) Dial

func (c *MockSSHClient) Dial(n, addr string) (net.Conn, error)

Dial attempts a connection to the specified address.

func (*MockSSHClient) DialCalls

func (c *MockSSHClient) DialCalls() int

DialCalls returns the number of times Dial was called.

type SyncBuffer

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

SyncBuffer is a bytes.Buffer protected by a mutex.

func (*SyncBuffer) Bytes

func (b *SyncBuffer) Bytes() []byte

Bytes returns the buffer's data as raw bytes.

func (*SyncBuffer) Read

func (b *SyncBuffer) Read(p []byte) (int, error)

Read implements io.Reader for SyncBuffer.

func (*SyncBuffer) String

func (b *SyncBuffer) String() string

String returns the buffer's data as a string.

func (*SyncBuffer) Write

func (b *SyncBuffer) Write(p []byte) (int, error)

Write implements io.Writer for SyncBuffer.

Jump to

Keyboard shortcuts

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