test

package
v3.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMockTransport

func AddMockTransport()

AddMockTransport registers the mock transport.

func AddrMock

func AddrMock() string

AddrMock returns a generic address for mock sockets.

func AddrTestIPC

func AddrTestIPC() string

AddrTestIPC returns a test IPC address. It will be in the temporary directory.

func AddrTestInp

func AddrTestInp() string

AddrTestInp returns an inproc address.

func AddrTestTCP

func AddrTestTCP() string

AddrTestTCP returns a TCP address.

func AddrTestTLS

func AddrTestTLS() string

AddrTestTLS returns a TLS over TCP address.

func AddrTestWS

func AddrTestWS() string

AddrTestWS returns a websocket address.

func AddrTestWSS

func AddrTestWSS() string

AddrTestWSS returns a websocket over TLS address.

func CannotRecv

func CannotRecv(t *testing.T, f func() (mangos.Socket, error))

CannotRecv verifies that the socket cannot recv.

func CannotSend

func CannotSend(t *testing.T, f func() (mangos.Socket, error))

CannotSend verifies that the socket cannot send.

func ConnectPair

func ConnectPair(t *testing.T, s1 mangos.Socket, s2 mangos.Socket)

ConnectPair is like ConnectPairVia but uses inproc.

func ConnectPairVia

func ConnectPairVia(t *testing.T, addr string, s1, s2 mangos.Socket, o1, o2 map[string]interface{})

ConnectPairVia connects two sockets using the given address. The pipe event hook is used for this operation, and the function does not return until both sockets have seen the connection.

func GetMockSocket

func GetMockSocket() protocol.Socket

GetMockSocket returns a mock socket.

func GetMockSocketEx

func GetMockSocketEx(proto uint16, name string) protocol.Socket

GetMockSocketEx returns a socket for a specific protocol.

func GetMockSocketRaw

func GetMockSocketRaw(proto, peer uint16, name, peerName string, raw interface{}, err error) protocol.Socket

GetMockSocketRaw is an extended form to get a mocked socket, with particular properties set (including the response to GetOption() for Raw.)

func GetSocket

func GetSocket(t *testing.T, f func() (mangos.Socket, error)) mangos.Socket

GetSocket returns a socket using the constructor function.

func GetTLSConfig

func GetTLSConfig(t *testing.T, server bool) *tls.Config

GetTLSConfig is like NewTLSConfig, but it caches to avoid regenerating key material pointlessly.

func MockAddPipe

func MockAddPipe(t *testing.T, s mangos.Socket, c MockCreator, p MockPipe) mangos.Pipe

MockAddPipe simulates adding a pipe.

func MockMustRecvStr

func MockMustRecvStr(t *testing.T, p MockPipe, str string, d time.Duration)

MockMustRecvStr ensures that the pipe receives a message with the payload equal to the string.

func MockMustSend

func MockMustSend(t *testing.T, p MockPipe, data []byte, d time.Duration)

MockMustSend ensures that the pipe sends a message with the body given.

func MockMustSendMsg

func MockMustSendMsg(t *testing.T, p MockPipe, m *mangos.Message, d time.Duration)

MockMustSendMsg ensures that the pipe sends a message.

func MockMustSendStr

func MockMustSendStr(t *testing.T, p MockPipe, str string, d time.Duration)

MockMustSendStr ensures that the pipe sends a message with a payload containing the given string.

func MustBeError

func MustBeError(t *testing.T, e error, compare error)

MustBeError verifies that a value is a specific error.

func MustBeFalse

func MustBeFalse(t *testing.T, b bool)

MustBeFalse verifies that the condition is true.

func MustBeNil

func MustBeNil(t *testing.T, v interface{})

MustBeNil verifies that the provided value is nil

func MustBeTrue

func MustBeTrue(t *testing.T, b bool)

MustBeTrue verifies that the condition is true.

func MustClose

func MustClose(t *testing.T, s mangos.Socket)

MustClose closes the socket.

func MustFail

func MustFail(t *testing.T, e error)

MustFail verifies that the error is not nil. If it is nil, the test is a fatal failure.

func MustGetInfo

func MustGetInfo(t *testing.T, f func() (mangos.Socket, error)) mangos.ProtocolInfo

MustGetInfo returns the Info for the socket.

func MustNotBeNil

func MustNotBeNil(t *testing.T, v interface{})

MustNotBeNil verifies that the provided value is not nil

func MustNotRecv

func MustNotRecv(t *testing.T, s mangos.Socket, err error)

func MustRecv

func MustRecv(t *testing.T, s mangos.Socket) []byte

func MustRecvMsg

func MustRecvMsg(t *testing.T, s mangos.Socket) *mangos.Message

func MustRecvString

func MustRecvString(t *testing.T, s mangos.Socket, m string)

func MustSend

func MustSend(t *testing.T, s mangos.Socket, b []byte)

func MustSendMsg

func MustSendMsg(t *testing.T, s mangos.Socket, m *mangos.Message)

func MustSendString

func MustSendString(t *testing.T, s mangos.Socket, m string)

func MustSucceed

func MustSucceed(t *testing.T, e error)

MustSucceed verifies that that the supplied error is nil. If it is not nil, we call t.Fatalf() to fail the test immediately.

func NewMockSocket

func NewMockSocket() (protocol.Socket, error)

NewMockSocket returns a mock socket, and nil.

func NextPort

func NextPort() uint32

NextPort returns the next port, incrementing by one.

func SetTTL

func SetTTL(t *testing.T, f func() (mangos.Socket, error))

SetTTL tests that we can set a valid TTL, and get the same value back.

func SetTTLNegative

func SetTTLNegative(t *testing.T, f func() (mangos.Socket, error))

SetTTLNegative tests that a given socket fails to set a negative TTL.

func SetTTLNotInt

func SetTTLNotInt(t *testing.T, f func() (mangos.Socket, error))

SetTTLNotInt tests that a given socket fails to set a non-integer TTL.

func SetTTLTooBig

func SetTTLTooBig(t *testing.T, f func() (mangos.Socket, error))

SetTTLTooBig tests that a given socket fails to set a very large TTL.

func SetTTLZero

func SetTTLZero(t *testing.T, f func() (mangos.Socket, error))

SetTTLZero tests that a given socket fails to set a TTL of zero.

func TTLDropTest

func TTLDropTest(t *testing.T,
	cli func() (mangos.Socket, error),
	srv func() (mangos.Socket, error),
	rawcli func() (mangos.Socket, error),
	rawsrv func() (mangos.Socket, error))

TTLDropTest is a generic test for dropping based on TTL expiration. F1 makes the Client socket, f2 makes the Server socket.

func TranConnHandshake

func TranConnHandshake(t *testing.T, c net.Conn, proto uint16)

TranConnHandshake just performs the handshake, the conn should be connected.

func TranSendBadMessages

func TranSendBadMessages(t *testing.T, proto uint16, isipc bool, dial func() (net.Conn, error))

TranSendBadMessages opens new connections and sends garbage to them.

func TranSendConnBadHandshakes

func TranSendConnBadHandshakes(t *testing.T, dial func() (net.Conn, error))

TranSendConnBadHandshakes just sends garbage handshakes.

func TranVerifyAcceptWithoutListen

func TranVerifyAcceptWithoutListen(t *testing.T, tran transport.Transport)

TranVerifyAcceptWithoutListen verifies that we can't call accept if we did not first call listen.

func TranVerifyAnonymousPort

func TranVerifyAnonymousPort(t *testing.T, addr string, dOpts, lOpts map[string]interface{})

TranVerifyAnonymousPort is used by TCP based transports to verify that using a wild card port address works. The addr is an address using a wild card port (usually port 0).

func TranVerifyBadAddress

func TranVerifyBadAddress(t *testing.T, addr string, dOpts, lOpts map[string]interface{})

TranVerifyBadAddress is used to verify that certain addresses are invalid and cannot be used for dialing or listening. This is useful, for example, when checking that DNS failures are handled properly.

func TranVerifyBadLocalAddress

func TranVerifyBadLocalAddress(t *testing.T, addr string, opts map[string]interface{})

TranVerifyBadLocalAddress is used to verify that a given address cannot be listened to. This could be for an address that we cannot resolve a name for, or an address that we do not have an IP address for. The failure can occur at either listener allocation time, or when trying to bind.

func TranVerifyBadRemoteAddress

func TranVerifyBadRemoteAddress(t *testing.T, addr string, opts map[string]interface{})

TranVerifyBadRemoteAddress is used to verify that a given address cannot be dialed to. This could be for an address that we cannot resolve a name for, or an address is known to be otherwise impossible or invalid.

func TranVerifyBoolOption

func TranVerifyBoolOption(t *testing.T, tran transport.Transport, name string)

TranVerifyBoolOption verifies that a bool option behaves properly.

func TranVerifyConnectionRefused

func TranVerifyConnectionRefused(t *testing.T, tran transport.Transport, opts map[string]interface{})

TranVerifyConnectionRefused verifies that connection is refused if no listener.

func TranVerifyDialInsecure

func TranVerifyDialInsecure(t *testing.T, tran transport.Transport)

TranVerifyDialInsecure verifies InsecureSkipVerify.

func TranVerifyDialNoCert

func TranVerifyDialNoCert(t *testing.T, tran transport.Transport)

TranVerifyDialNoCert verifies that we fail to dial if we lack a Server cert.

func TranVerifyDuplicateListen

func TranVerifyDuplicateListen(t *testing.T, tran transport.Transport, opts map[string]interface{})

TranVerifyDuplicateListen verifies that we can't bind to the same address twice.

func TranVerifyDurationOption

func TranVerifyDurationOption(t *testing.T, tran transport.Transport, name string)

TranVerifyDurationOption verifies that a time.Duration option behaves properly.

func TranVerifyHandshakeFail

func TranVerifyHandshakeFail(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifyHandshakeFail verifies that we fail if the protocols mismatch.

func TranVerifyIntOption

func TranVerifyIntOption(t *testing.T, tran transport.Transport, name string)

TranVerifyIntOption verifies that an int option behaves properly.

func TranVerifyInvalidOption

func TranVerifyInvalidOption(t *testing.T, tran transport.Transport)

TranVerifyInvalidOption verifies that an invalid option behaves properly.

func TranVerifyKeepAliveOption

func TranVerifyKeepAliveOption(t *testing.T, tran transport.Transport)

TranVerifyKeepAliveOption verifies that keep alive options work.

func TranVerifyListenAndAccept

func TranVerifyListenAndAccept(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifyListenAndAccept verifies that we can establish the connection.

func TranVerifyListenerClosed

func TranVerifyListenerClosed(t *testing.T, tran transport.Transport, opts map[string]interface{})

TranVerifyListenerClosed verifies that the listener behaves after closed.

func TranVerifyMaxRecvSize

func TranVerifyMaxRecvSize(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifyMaxRecvSize verifies the transport handles maximum receive size properly.

func TranVerifyMessageHeader

func TranVerifyMessageHeader(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifyMessageHeader verifies that message headers are transmitted.

func TranVerifyMessageSizes

func TranVerifyMessageSizes(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifyMessageSizes verifies we can transport a variety of message sizes

func TranVerifyNoDelayOption

func TranVerifyNoDelayOption(t *testing.T, tran transport.Transport)

TranVerifyNoDelayOption verifies that NoDelay is always true.

func TranVerifyPipeAddresses

func TranVerifyPipeAddresses(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifyPipeAddresses performs basic validation of pipe address options.

func TranVerifyPipeOptions

func TranVerifyPipeOptions(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifyPipeOptions verifies that the LocalAddr, RemoteAddr and invalid options all behave as we expect.

func TranVerifyPipeOptions2

func TranVerifyPipeOptions2(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifyPipeOptions2 verifies standard pipe Options.

func TranVerifyScheme

func TranVerifyScheme(t *testing.T, tran transport.Transport)

TranVerifyScheme verifies that we get the right scheme. It also tries an invalid scheme.

func TranVerifySendRecv

func TranVerifySendRecv(t *testing.T, tran transport.Transport, dOpts, lOpts map[string]interface{})

TranVerifySendRecv just verifies basic send and receive.

func TranVerifyTLSConfigOption

func TranVerifyTLSConfigOption(t *testing.T, tran transport.Transport)

TranVerifyTLSConfigOption verifies that OptionTLSConfig works properly.

func VerifyClosedAddPipe

func VerifyClosedAddPipe(t *testing.T, f func() (mangos.Socket, error))

func VerifyClosedClose

func VerifyClosedClose(t *testing.T, f func() (mangos.Socket, error))

VerifyClosedClose verifies that Close on an already closed socket returns protocol.ErrClosed.

func VerifyClosedContext

func VerifyClosedContext(t *testing.T, f func() (mangos.Socket, error))

func VerifyClosedDial

func VerifyClosedDial(t *testing.T, f func() (mangos.Socket, error))

VerifyClosedDial verifies that Dial returns protocol.ErrClosed on a closed socket.

func VerifyClosedListen

func VerifyClosedListen(t *testing.T, f func() (mangos.Socket, error))

VerifyClosedListen verifies that Listen returns protocol.ErrClosed on a closed socket.

func VerifyClosedRecv

func VerifyClosedRecv(t *testing.T, f func() (mangos.Socket, error))

VerifyClosedRecv verifies that Recv on the socket created returns protocol.ErrClosed if it is closed.

func VerifyClosedSend

func VerifyClosedSend(t *testing.T, f func() (mangos.Socket, error))

VerifyClosedSend verifies that Send on the socket created returns protocol.ErrClosed if it is closed.

func VerifyCooked

func VerifyCooked(t *testing.T, f func() (mangos.Socket, error))

VerifyCooked verifies that the socket created is cooked, and cannot be changed to raw.

func VerifyInvalidOption

func VerifyInvalidOption(t *testing.T, f func() (mangos.Socket, error))

VerifyInvalidOption verifies that invalid options fail.

func VerifyMaxRx

func VerifyMaxRx(t *testing.T, addr string, makePair func() (mangos.Socket, error))

VerifyMaxRx is used to test that the transport enforces the maximum receive size. In order to avoid challenges, this has to be pair.

func VerifyOptionBool

func VerifyOptionBool(t *testing.T, f func() (mangos.Socket, error), option string)

VerifyOptionBool validates bool options.

func VerifyOptionDuration

func VerifyOptionDuration(t *testing.T, f func() (mangos.Socket, error), option string)

VerifyOptionDuration validates time.Duration options

func VerifyOptionInt

func VerifyOptionInt(t *testing.T, f func() (mangos.Socket, error), option string)

VerifyOptionInt validates integer options.

func VerifyOptionMaxRecvSize

func VerifyOptionMaxRecvSize(t *testing.T, f func() (mangos.Socket, error))

VerifyOptionMaxRecvSize validates OptionMaxRecvSize.

func VerifyOptionQLen

func VerifyOptionQLen(t *testing.T, f func() (mangos.Socket, error), option string)

VerifyOptionQLen validates queue length options.

func VerifyOptionTTL

func VerifyOptionTTL(t *testing.T, f func() (mangos.Socket, error))

VerifyOptionTTL validates OptionTTL.

func VerifyRaw

func VerifyRaw(t *testing.T, f func() (mangos.Socket, error))

VerifyRaw verifies that the socket created is raw, and cannot be changed to cooked.

Types

type KeyPair

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

KeyPair is a single public key pair

func (*KeyPair) CertPEM

func (k *KeyPair) CertPEM() []byte

func (*KeyPair) KeyPEM

func (k *KeyPair) KeyPEM() []byte

func (*KeyPair) PubKeyPEM added in v3.4.1

func (k *KeyPair) PubKeyPEM() []byte

type Keys

type Keys struct {
	Root   KeyPair // Root CA key pair
	Server KeyPair // Server key pair
	Client KeyPair // Client key pair
}

Keys is a set of the Root, Server, and Client keys for a test config.

func GetTLSConfigKeys

func GetTLSConfigKeys(t *testing.T) (*tls.Config, *tls.Config, *Keys)

GetTLSConfigKeys is like NewTLSConfig, but it caches to avoid regenerating key material pointlessly. It also returns the Keys.

func NewTLSConfig

func NewTLSConfig() (*tls.Config, *tls.Config, *Keys, error)

NewTLSConfig creates a suitable TLS configuration, using either a Server or Client.

type MockCreator

type MockCreator interface {
	// NewPipe creates a Pipe, but does not add it.  The pipe will
	// use the assigned peer protocol.
	NewPipe(peer uint16) MockPipe

	// AddPipe adds the given pipe, returning an error if there is
	// no room to do so in the pipeQ.
	AddPipe(pipe MockPipe) error

	// DeferClose is used to defer close operations.  If Close()
	// is called, and deferring is false, then the close
	// will happen immediately.
	DeferClose(deferring bool)

	// Close is used to close the creator.
	Close() error

	// Dial simulates dialing
	Dial() (transport.Pipe, error)

	// Listen simulates listening
	Listen() error

	// Accept simulates accepting.
	Accept() (transport.Pipe, error)

	// GetOption simulates getting an option.
	GetOption(string) (interface{}, error)

	// SetOption simulates setting an option.
	SetOption(string, interface{}) error

	// Address returns the address.
	Address() string

	// InjectError is used to inject a single error.
	InjectError(error)
}

MockCreator is an abstraction of both dialers and listeners, which allows us to test various transport failure conditions.

func GetMockDialer

func GetMockDialer(t *testing.T, s mangos.Socket) (mangos.Dialer, MockCreator)

GetMockDialer returns a dialer that creates mock pipes.

func GetMockListener

func GetMockListener(t *testing.T, s mangos.Socket) (mangos.Listener, MockCreator)

GetMockListener returns a listener that creates mock pipes.

type MockPipe

type MockPipe interface {
	// SendQ obtains the send queue.  Test code can read from this
	// to get messages sent by the socket.
	SendQ() <-chan *protocol.Message

	// RecvQ obtains the recv queue.  Test code can write to this
	// to send message to the socket.
	RecvQ() chan<- *protocol.Message

	// InjectSendError is used to inject an error that will be seen
	// by the next Send() operation.
	InjectSendError(error)

	// InjectRecvError is used to inject an error that will be seen
	// by the next Recv() operation.
	InjectRecvError(error)

	// DeferClose defers closing.
	DeferClose(deferring bool)

	// MockSendMsg lets us inject a message into the queue.
	MockSendMsg(*protocol.Message, time.Duration) error

	// MockRecvMsg lets us attempt to receive a message.
	MockRecvMsg(time.Duration) (*protocol.Message, error)

	transport.Pipe
}

MockPipe is a mocked transport pipe.

func MockConnect

func MockConnect(t *testing.T, s mangos.Socket) (MockPipe, mangos.Pipe)

MockConnect simulates connecting a pipe.

func NewMockPipe

func NewMockPipe(lProto, rProto uint16) MockPipe

NewMockPipe creates a mocked transport pipe.

Jump to

Keyboard shortcuts

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