mock

package
v0.0.0-...-56e997f Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package mock is an alternative VPP adapter aimed for unit/integration testing where the actual communication with VPP is not demanded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageDTO

type MessageDTO struct {
	MsgID    uint16
	MsgName  string
	ClientID uint32
	Data     []byte
}

MessageDTO is a structure used for propagating information to ReplyHandlers.

type MsgWithContext

type MsgWithContext struct {
	Msg       api.Message
	SeqNum    uint16
	Multipart bool
	// contains filtered or unexported fields
}

MsgWithContext encapsulates reply message with possibly sequence number and is-multipart flag.

type ReplyHandler

type ReplyHandler func(request MessageDTO) (reply []byte, msgID uint16, ok bool)

ReplyHandler is a type that allows to extend the behaviour of VPP mock. Return value ok is used to signalize that mock reply is calculated and ready to be used.

type VppAdapter

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

VppAdapter represents a mock VPP adapter that can be used for unit/integration testing instead of the vppapiclient adapter.

func NewVppAdapter

func NewVppAdapter() *VppAdapter

NewVppAdapter returns a new mock adapter.

func (*VppAdapter) Connect

func (a *VppAdapter) Connect() error

Connect emulates connecting the process to VPP.

func (*VppAdapter) Disconnect

func (a *VppAdapter) Disconnect()

Disconnect emulates disconnecting the process from VPP.

func (*VppAdapter) GetMsgID

func (a *VppAdapter) GetMsgID(msgName string, msgCrc string) (uint16, error)

GetMsgID returns mocked message ID for the given message name and CRC.

func (*VppAdapter) GetMsgNameByID

func (a *VppAdapter) GetMsgNameByID(msgID uint16) (string, bool)

GetMsgNameByID returns message name for specified message ID.

func (*VppAdapter) MockReply

func (a *VppAdapter) MockReply(msgs ...api.Message)

MockReply stores a message or a list of multipart messages to be returned when the next request comes. It is a FIFO queue - multiple replies can be pushed into it, the first message or the first set of multi-part messages will be popped when some request comes. Using of this method automatically switches the mock into the useRepliesQueue mode.

Note: multipart requests are implemented using two requests actually - the multipart request itself followed by control ping used to tell which multipart message is the last one. A mock reply to a multipart request has to thus consist of exactly two calls of this method. For example:

   mockVpp.MockReply(  // push multipart messages all at once
			&interfaces.SwInterfaceDetails{SwIfIndex:1},
			&interfaces.SwInterfaceDetails{SwIfIndex:2},
			&interfaces.SwInterfaceDetails{SwIfIndex:3},
   )
   mockVpp.MockReply(&vpe.ControlPingReply{})

Even if the multipart request has no replies, MockReply has to be called twice:

mockVpp.MockReply()  // zero multipart messages
mockVpp.MockReply(&vpe.ControlPingReply{})

func (*VppAdapter) MockReplyHandler

func (a *VppAdapter) MockReplyHandler(replyHandler ReplyHandler)

MockReplyHandler registers a handler function that is supposed to generate mock responses to incoming requests. Using of this method automatically switches the mock into th useReplyHandlers mode.

func (*VppAdapter) MockReplyWithContext

func (a *VppAdapter) MockReplyWithContext(msgs ...MsgWithContext)

MockReplyWithContext queues next reply like MockReply() does, except that the sequence number and multipart flag (= context minus channel ID) can be customized and not necessarily match with the request. The purpose of this function is to test handling of sequence numbers and as such it is not really meant to be used outside the govpp UTs.

func (*VppAdapter) ReplyBytes

func (a *VppAdapter) ReplyBytes(request MessageDTO, reply api.Message) ([]byte, error)

ReplyBytes encodes the mocked reply into binary format.

func (*VppAdapter) ReplyFor

func (a *VppAdapter) ReplyFor(requestMsgName string) (api.Message, uint16, bool)

ReplyFor returns reply message for given request message name.

func (*VppAdapter) ReplyTypeFor

func (a *VppAdapter) ReplyTypeFor(requestMsgName string) (reflect.Type, uint16, bool)

ReplyTypeFor returns reply message type for given request message name.

func (*VppAdapter) SendMsg

func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error

SendMsg emulates sending a binary-encoded message to VPP.

func (*VppAdapter) SetMsgCallback

func (a *VppAdapter) SetMsgCallback(cb adapter.MsgCallback)

SetMsgCallback sets a callback function that will be called by the adapter whenever a message comes from the mock.

func (*VppAdapter) WaitReady

func (a *VppAdapter) WaitReady() error

WaitReady mocks waiting for VPP

Directories

Path Synopsis
Package binapi is a helper package for generic handling of VPP binary API messages in the mock adapter and integration tests.
Package binapi is a helper package for generic handling of VPP binary API messages in the mock adapter and integration tests.

Jump to

Keyboard shortcuts

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