mock

package
v0.0.0-...-96fae21 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mock implements necessary mocking structures to allow easier testing for the smpp package. Only ReadWriteCloser is currently implemented aimed at mocking network connection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	io.ReadWriteCloser
	// contains filtered or unexported fields
}

Conn implements ReadWriteCloser interface and can be used to mock network connection in tests.

func NewConn

func NewConn() *Conn

NewConn instantiates mocked connection.

func (*Conn) ByteRead

func (c *Conn) ByteRead(read []byte) *Conn

ByteRead will set connection to respond with provided bytes.

func (*Conn) ByteWrite

func (c *Conn) ByteWrite(write []byte) *Conn

ByteWrite will set connection to expect provided bytes for write.

func (*Conn) Close

func (c *Conn) Close() error

Close implements closer interface.

func (*Conn) Closed

func (c *Conn) Closed() *Conn

Closed will set connection to expect call to Close.

func (*Conn) ErrRead

func (c *Conn) ErrRead(err error) *Conn

ErrRead will set connection to fail read with provided error.

func (*Conn) ErrWrite

func (c *Conn) ErrWrite(err error) *Conn

ErrWrite will set connection to fail write with error.

func (*Conn) NoResp

func (c *Conn) NoResp() *Conn

NoResp will set connection to not return response for the preceding read/write. Panics if write/read calls are unmatched.

func (*Conn) ProcessRead

func (c *Conn) ProcessRead(f func(step, count int) ([]byte, error)) *Conn

ProcessRead provides function to the connection that will process read.

func (*Conn) ProcessWrite

func (c *Conn) ProcessWrite(f func(step, count int) ([]byte, error)) *Conn

ProcessWrite provides function to the connection that will process writes.

func (*Conn) Read

func (c *Conn) Read(out []byte) (int, error)

func (*Conn) Times

func (c *Conn) Times(n int) *Conn

Times multiplies last step n times.

func (*Conn) Validate

func (c *Conn) Validate() []error

Validate will check executed scenario and return any errors in execution. It will return nil if scenario was valid.

func (*Conn) Wait

func (c *Conn) Wait(s int) *Conn

Wait acts on the last chained step and it instructs mock to wait for the indexed step to complete before the one Wait was called on.

func (*Conn) Write

func (c *Conn) Write(in []byte) (int, error)

Write implements io.Writer interface.

Jump to

Keyboard shortcuts

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