mock

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 8 Imported by: 25

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 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) ([]adapter.StatIdentifier, error)

ListStats mocks name listing for all stats.

func (*StatsAdapter) MockDir added in v0.2.0

func (a *StatsAdapter) MockDir(dir *adapter.StatDir)

MockStats sets mocked stat dir to be returned by PrepareDir.

func (*StatsAdapter) MockStats

func (a *StatsAdapter) MockStats(stats []adapter.StatEntry)

MockStats sets mocked stat entries to be returned by DumpStats.

func (*StatsAdapter) PrepareDir added in v0.2.0

func (a *StatsAdapter) PrepareDir(prefixes ...string) (*adapter.StatDir, error)

func (*StatsAdapter) PrepareDirOnIndex added in v0.4.0

func (a *StatsAdapter) PrepareDirOnIndex(indexes ...uint32) (*adapter.StatDir, error)

func (*StatsAdapter) UpdateDir added in v0.2.0

func (a *StatsAdapter) UpdateDir(dir *adapter.StatDir) error

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 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() 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) MockClearReplyHandlers added in v0.2.0

func (a *VppAdapter) MockClearReplyHandlers()

MockClearReplyHanders clears all reply handlers that were registered Will also set the mode to useReplyHandlers

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(pkg, requestMsgName string) (api.Message, uint16, bool)

ReplyFor returns reply message for given request message name.

func (*VppAdapter) ReplyTypeFor

func (a *VppAdapter) ReplyTypeFor(pkg, 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