package fake

import "github.com/Azure/go-amqp/internal/fake"

Index

Variables

var ErrAlreadyClosed = errors.New("fake already closed")

ErrAlreadyClosed is returned by Close() if NetConn is already closed.

Functions

func EncodeFrame

func EncodeFrame(t frames.Type, channel uint16, f frames.FrameBody) ([]byte, error)

EncodeFrame encodes the specified frame to be sent over the wire.

func PerformBegin

func PerformBegin(channel, remoteChannel uint16) ([]byte, error)

PerformBegin appends a PerformBegin frame with the specified remote channel ID. This frame is needed when making a call to Client.NewSession().

func PerformClose

func PerformClose(e *encoding.Error) ([]byte, error)

PerformClose encodes a PerformClose frame with an optional error.

func PerformDetach

func PerformDetach(channel uint16, linkHandle uint32, e *encoding.Error) ([]byte, error)

PerformDetach encodes a PerformDetach frame with an optional error.

func PerformDisposition

func PerformDisposition(role encoding.Role, channel uint16, firstID uint32, lastID *uint32, state encoding.DeliveryState) ([]byte, error)

PerformDisposition appends a PerformDisposition frame with the specified values. The firstID MUST match the deliveryID value specified in PerformTransfer.

func PerformEnd

func PerformEnd(channel uint16, e *encoding.Error) ([]byte, error)

PerformEnd encodes a PerformEnd frame with an optional error.

func PerformOpen

func PerformOpen(containerID string) ([]byte, error)

PerformOpen appends a PerformOpen frame with the specified container ID. This frame, and ProtoHeader, are needed when calling amqp.New() to create a client.

func PerformTransfer

func PerformTransfer(channel uint16, linkHandle, deliveryID uint32, payload []byte) ([]byte, error)

PerformTransfer appends a PerformTransfer frame with the specified values. The linkHandle MUST match the linkHandle value specified in ReceiverAttach.

func ProtoHeader

func ProtoHeader(id ProtoID) ([]byte, error)

ProtoHeader adds the initial handshake frame to the list of responses. This frame, and PerformOpen, are needed when calling amqp.New() to create a client.

func ReceiverAttach

func ReceiverAttach(channel uint16, linkName string, linkHandle uint32, mode encoding.ReceiverSettleMode, filter encoding.Filter) ([]byte, error)

ReceiverAttach appends a PerformAttach frame with the specified values. This frame is needed when making a call to Session.NewReceiver().

func SenderAttach

func SenderAttach(channel uint16, linkName string, linkHandle uint32, mode encoding.SenderSettleMode) ([]byte, error)

SenderAttach encodes a PerformAttach frame with the specified values. This frame is needed when making a call to Session.NewSender().

Types

type AMQPProto

type AMQPProto struct {
	frames.FrameBody
}

AMQPProto is the frame type passed to FrameCallback() for the initial protocal handshake.

type KeepAlive

type KeepAlive struct {
	frames.FrameBody
}

KeepAlive is the frame type passed to FrameCallback() for keep-alive frames.

type NetConn

type NetConn struct {
	// OnClose is called from Close() before it returns.
	// The value returned from OnClose is returned from Close().
	OnClose func() error

	// ReadErr is used to simulate a connReader error.
	// The error written to this channel is returned
	// from the call to NetConn.Read.
	ReadErr chan error

	// WriteErr is used to simulate a connWriter error.
	// The error sent here is returned from the call to NetConn.Write.
	// Has a buffer of one so setting a pending error won't block.
	WriteErr chan error
	// contains filtered or unexported fields
}

NetConn is a fake network connection that satisfies the net.Conn interface.

func NewNetConn

func NewNetConn(resp func(remoteChannel uint16, fr frames.FrameBody) (Response, error), opts NetConnOptions) *NetConn

NewNetConn creates a new instance of NetConn. Responder is invoked by Write when a frame is received. Return a zero-value Response/nil error to swallow the frame. Return a non-nil error to simulate a write error. NOTE: resp is called on a separate goroutine so it MUST NOT access any *testing.T etc

func (*NetConn) Close

func (n *NetConn) Close() error

Close is called by conn.close.

func (*NetConn) LocalAddr

func (n *NetConn) LocalAddr() net.Addr

func (*NetConn) Read

func (n *NetConn) Read(b []byte) (int, error)

Read is invoked by conn.connReader to recieve frame data. It blocks until Write or Close are called, or the read deadline expires which will return an error.

func (*NetConn) RemoteAddr

func (n *NetConn) RemoteAddr() net.Addr

func (*NetConn) SendFrame

func (n *NetConn) SendFrame(f []byte)

SendFrame sends the encoded frame to the client. Use this to send a frame at an arbitrary time.

func (*NetConn) SendKeepAlive

func (n *NetConn) SendKeepAlive()

SendKeepAlive sends a keep-alive frame to the client.

func (*NetConn) SendMultiFrameTransfer

func (n *NetConn) SendMultiFrameTransfer(channel uint16, linkHandle, deliveryID uint32, payload []byte, edit func(int, *frames.PerformTransfer)) error

SendMultiFrameTransfer splits payload into 32-byte chunks, encodes, and sends to the client. Payload must be big enough for at least two chunks.

func (*NetConn) SetDeadline

func (n *NetConn) SetDeadline(t time.Time) error

func (*NetConn) SetReadDeadline

func (n *NetConn) SetReadDeadline(t time.Time) error

func (*NetConn) SetWriteDeadline

func (n *NetConn) SetWriteDeadline(t time.Time) error

func (*NetConn) Write

func (n *NetConn) Write(b []byte) (int, error)

Write is invoked by conn.connWriter when we're being sent frame data. Every call to Write will invoke the responder callback that must reply with one of three possibilities.

  1. an encoded frame and nil error
  2. a non-nil error to similate a write failure
  3. a nil slice and nil error indicating the frame should be ignored

type NetConnOptions

type NetConnOptions struct {
	// ChunkSize is the size of chunks to split responses into.
	// A zero or negative value means no chunking.
	// The default value is zero.
	ChunkSize int
}

NetConnOptions contains options when creating a NetConn. Pass the zero-value to accept the default values.

type ProtoID

type ProtoID uint8

ProtoID indicates the type of protocol (copied from conn.go)

const (
	ProtoAMQP ProtoID = 0x0
	ProtoTLS  ProtoID = 0x2
	ProtoSASL ProtoID = 0x3
)

type Response

type Response struct {
	// Payload is the marshalled frame to send to Conn.connReader
	Payload []byte

	// WriteDelay is the duration to wait before writing Payload.
	// Use this to introduce a delay when waiting for a response.
	WriteDelay time.Duration

	// ChunkSize is the size of chunks to split Payload into.
	// A zero or negative value means no chunking.
	// This value supercedes the NetConnOptions.ChunkSize.
	ChunkSize int
}

Response is the response returned from a responder function.

Source Files

net_conn.go

Version
v1.4.0 (latest)
Published
Feb 19, 2025
Platform
linux/amd64
Imports
7 packages
Last checked
5 days ago

Tools for package owners.