testingutils

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LocalAddr  = FakeAddr(1)
	RemoteAddr = FakeAddr(2)
)
View Source
var (
	ErrWriteTimeout = &NetError{msg: "websocket: write timeout", timeout: true, temporary: true}
)

Functions

func DecodeMsg

func DecodeMsg(codec sabuhp.Codec, data []byte) (sabuhp.Message, error)

func EncodedMsg

func EncodedMsg(codec sabuhp.Codec, topic sabuhp.Topic, message string, fromAddr string) ([]byte, error)

func GetWSMessage

func GetWSMessage(t *testing.T, ws *websocket.Conn) ([]byte, error)

func HttpToWS

func HttpToWS(t *testing.T, u string) string

func Msg

func Msg(topic sabuhp.Topic, message string, fromAddr string) sabuhp.Message

func NewTestConn

func NewTestConn(r io.Reader, w io.Writer, isServer bool) *websocket.Conn

NewTestConn creates a connection backed by a fake network connection using default values for buffering.

func NewWSServer

func NewWSServer(t *testing.T, h http.Handler) (*httptest.Server, *websocket.Conn)

func NewWSServerOnly

func NewWSServerOnly(t *testing.T, h http.Handler) (*httptest.Server, string)

NewWSServerOnly returns websocket http server and url for connecting.

func ReceiveMsg

func ReceiveMsg(t *testing.T, ws *websocket.Conn, codec sabuhp.Codec) (sabuhp.Message, error)

func ReceiveWSMessage

func ReceiveWSMessage(t *testing.T, ws *websocket.Conn) []byte

func SendMessage

func SendMessage(t *testing.T, ws *websocket.Conn, msg []byte)

Types

type FakeAddr

type FakeAddr int

func (FakeAddr) Network

func (a FakeAddr) Network() string

func (FakeAddr) String

func (a FakeAddr) String() string

type FakeNetConn

type FakeNetConn struct {
	io.Reader
	io.Writer
}

func (FakeNetConn) Close

func (c FakeNetConn) Close() error

func (FakeNetConn) LocalAddr

func (c FakeNetConn) LocalAddr() net.Addr

func (FakeNetConn) RemoteAddr

func (c FakeNetConn) RemoteAddr() net.Addr

func (FakeNetConn) SetDeadline

func (c FakeNetConn) SetDeadline(t time.Time) error

func (FakeNetConn) SetReadDeadline

func (c FakeNetConn) SetReadDeadline(t time.Time) error

func (FakeNetConn) SetWriteDeadline

func (c FakeNetConn) SetWriteDeadline(t time.Time) error

type LoggerPub

type LoggerPub struct{}

func (LoggerPub) Log

func (l LoggerPub) Log(cb *njson.JSON)

type NetError

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

NetError satisfies the net Error interface.

func (*NetError) Error

func (e *NetError) Error() string

func (*NetError) Temporary

func (e *NetError) Temporary() bool

func (*NetError) Timeout

func (e *NetError) Timeout() bool

type SubChannel

type SubChannel struct {
	T       string
	G       string
	Handler sabuhp.TransportResponse
}

func (SubChannel) Close

func (s SubChannel) Close()

func (SubChannel) Err

func (s SubChannel) Err() error

func (SubChannel) Group

func (s SubChannel) Group() string

func (SubChannel) Topic

func (s SubChannel) Topic() string

type TransportImpl

type TransportImpl struct {
	ConnFunc      func() sabuhp.Conn
	SendToOneFunc func(data *sabuhp.Message, timeout time.Duration) error
	SendToAllFunc func(data *sabuhp.Message, timeout time.Duration) error
	ListenFunc    func(topic string, handler sabuhp.TransportResponse) sabuhp.Channel
}

func (TransportImpl) Conn

func (t TransportImpl) Conn() sabuhp.Conn

func (TransportImpl) Listen

func (t TransportImpl) Listen(topic string, handler sabuhp.TransportResponse) sabuhp.Channel

func (TransportImpl) SendToAll

func (t TransportImpl) SendToAll(data *sabuhp.Message, timeout time.Duration) error

func (TransportImpl) SendToOne

func (t TransportImpl) SendToOne(data *sabuhp.Message, timeout time.Duration) error

Jump to

Keyboard shortcuts

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