Documentation ¶
Overview ¶
Package mock is an alternative VPP adapter aimed for unit/integration testing where the actual communication with VPP is not demanded.
Index ¶
- type MessageDTO
- type MsgWithContext
- type ReplyHandler
- type StatsAdapter
- type VppAdapter
- func (a *VppAdapter) Connect() error
- func (a *VppAdapter) Disconnect() error
- func (a *VppAdapter) GetMsgID(msgName string, msgCrc string) (uint16, error)
- func (a *VppAdapter) GetMsgNameByID(msgID uint16) (string, bool)
- func (a *VppAdapter) MockReply(msgs ...api.Message)
- func (a *VppAdapter) MockReplyHandler(replyHandler ReplyHandler)
- func (a *VppAdapter) MockReplyWithContext(msgs ...MsgWithContext)
- func (a *VppAdapter) ReplyBytes(request MessageDTO, reply api.Message) ([]byte, error)
- func (a *VppAdapter) ReplyFor(requestMsgName string) (api.Message, uint16, bool)
- func (a *VppAdapter) ReplyTypeFor(requestMsgName string) (reflect.Type, uint16, bool)
- func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error
- func (a *VppAdapter) SetMsgCallback(cb adapter.MsgCallback)
- func (a *VppAdapter) WaitReady() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MessageDTO ¶
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 StatsAdapter ¶
type StatsAdapter struct {
// contains filtered or unexported fields
}
StatsAdapter simulates VPP stats socket from which stats can be read
func NewStatsAdapter ¶
func NewStatsAdapter() *StatsAdapter
NewStatsAdapter returns a new mock stats adapter.
func (*StatsAdapter) Connect ¶
func (a *StatsAdapter) Connect() error
Connect mocks client connection to the stats API.
func (*StatsAdapter) Disconnect ¶
func (a *StatsAdapter) Disconnect() error
Disconnect mocks client connection termination.
func (*StatsAdapter) DumpStats ¶
func (a *StatsAdapter) DumpStats(patterns ...string) ([]*adapter.StatEntry, error)
DumpStats mocks all stat entries dump.
func (*StatsAdapter) ListStats ¶
func (a *StatsAdapter) ListStats(patterns ...string) ([]string, error)
ListStats mocks name listing for all stats.
func (*StatsAdapter) MockStats ¶
func (a *StatsAdapter) MockStats(stats []*adapter.StatEntry)
MockStats replaces current values of all supported stats by provided value
type VppAdapter ¶
type VppAdapter struct {
// contains filtered or unexported fields
}
VppAPI represents a mock VPP adapter that can be used for unit/integration testing instead of the vppapiclient adapter.
func (*VppAdapter) Connect ¶
func (a *VppAdapter) Connect() error
Connect emulates connecting the process to VPP.
func (*VppAdapter) Disconnect ¶
func (a *VppAdapter) Disconnect() error
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) ReplyTypeFor ¶
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