test

package
v1.6.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockCheckpointer

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

MockCheckpointer provides a thread-safe mock implementation of Checkpointer for testing. It tracks checkpoints and allows configuring errors and validation behavior.

func NewMockCheckpointer

func NewMockCheckpointer() *MockCheckpointer

NewMockCheckpointer creates a new mock checkpointer instance

func (*MockCheckpointer) Checkpoint

func (m *MockCheckpointer) Checkpoint(ctx context.Context, name string, sequenceNumber uint64) error

Checkpoint implements the Checkpointer interface

func (*MockCheckpointer) GetCheckpoint

func (m *MockCheckpointer) GetCheckpoint(ctx context.Context, name string) (uint64, error)

GetCheckpoint implements the Checkpointer interface

func (*MockCheckpointer) GetStoredCheckpoint

func (m *MockCheckpointer) GetStoredCheckpoint(name string) (uint64, error)

GetStoredCheckpoint returns the currently stored checkpoint value

func (*MockCheckpointer) OnCheckpointGet

func (m *MockCheckpointer) OnCheckpointGet(callback func(name string))

OnCheckpointGet sets a callback to be called when GetCheckpoint is called

func (*MockCheckpointer) OnCheckpointSet

func (m *MockCheckpointer) OnCheckpointSet(callback func(name string, value uint64))

OnCheckpointSet sets a callback to be called when Checkpoint is called

func (*MockCheckpointer) Reset

func (m *MockCheckpointer) Reset()

Reset clears all stored checkpoints and configured errors

func (*MockCheckpointer) SetCheckpoint

func (m *MockCheckpointer) SetCheckpoint(name string, value uint64)

SetCheckpoint directly sets a checkpoint value

func (*MockCheckpointer) SetCheckpointError

func (m *MockCheckpointer) SetCheckpointError(name string, err error)

SetCheckpointError configures an error to be returned by Checkpoint

func (*MockCheckpointer) SetGetCheckpointError

func (m *MockCheckpointer) SetGetCheckpointError(name string, err error)

SetGetCheckpointError configures an error to be returned by GetCheckpoint

type MockLogStreamServer

type MockLogStreamServer struct{}

MockLogStreamServer implements a minimal logstream.Server for testing

func (*MockLogStreamServer) GetLogStream

type MockMessageCreator

type MockMessageCreator struct {
	// Error if set, CreateMessage will return this error
	Error error

	// Message if set, CreateMessage will return this message
	// If nil and Error is nil, a default BidResult message is returned
	Message *envelope.Message
}

MockMessageCreator provides a configurable implementation of MessageCreator for testing. It allows setting predefined messages or errors to be returned.

func (*MockMessageCreator) CreateMessage

func (c *MockMessageCreator) CreateMessage(event watcher.Event) (*envelope.Message, error)

CreateMessage implements nclprotocol.MessageCreator

func (*MockMessageCreator) SetNextMessage

func (c *MockMessageCreator) SetNextMessage(msg *envelope.Message)

SetNextMessage configures the next message to be returned by CreateMessage

type MockMessageCreatorFactory

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

MockMessageCreatorFactory manages MockMessageCreator instances for testing. It provides a thread-safe way to create and configure message creators per node.

func NewMockMessageCreatorFactory

func NewMockMessageCreatorFactory(nodeID string) *MockMessageCreatorFactory

NewMockMessageCreatorFactory creates a new factory that validates against the given nodeID

func (*MockMessageCreatorFactory) CreateMessageCreator

func (f *MockMessageCreatorFactory) CreateMessageCreator(ctx context.Context, nodeID string) (nclprotocol.MessageCreator, error)

CreateMessageCreator implements nclprotocol.MessageCreatorFactory. Returns the mock creator if nodeID matches, error otherwise.

func (*MockMessageCreatorFactory) GetCreator

GetCreator provides access to the underlying mock creator for configuration

func (*MockMessageCreatorFactory) SetCreateError

func (f *MockMessageCreatorFactory) SetCreateError(err error)

SetCreateError configures an error to be returned by CreateMessageCreator

type MockMessageHandler

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

MockMessageHandler provides a configurable mock message handler for testing. It records messages received and allows configuring errors and processing behavior.

func NewMockMessageHandler

func NewMockMessageHandler() *MockMessageHandler

NewMockMessageHandler creates a new mock message handler

func (*MockMessageHandler) GetMessages

func (m *MockMessageHandler) GetMessages() []envelope.Message

GetMessages returns a copy of all messages received

func (*MockMessageHandler) HandleMessage

func (m *MockMessageHandler) HandleMessage(ctx context.Context, msg *envelope.Message) error

HandleMessage implements ncl.MessageHandler

func (*MockMessageHandler) SetError

func (m *MockMessageHandler) SetError(err error)

SetError configures an error to be returned by HandleMessage

func (*MockMessageHandler) ShouldProcess

func (m *MockMessageHandler) ShouldProcess(ctx context.Context, msg *envelope.Message) bool

ShouldProcess implements ncl.MessageHandler

type MockNodeInfoProvider

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

func NewMockNodeInfoProvider

func NewMockNodeInfoProvider() *MockNodeInfoProvider

NewMockNodeInfoProvider creates a new mock node info provider

func (*MockNodeInfoProvider) GetNodeInfo

func (m *MockNodeInfoProvider) GetNodeInfo(ctx context.Context) models.NodeInfo

func (*MockNodeInfoProvider) SetNodeInfo

func (m *MockNodeInfoProvider) SetNodeInfo(nodeInfo models.NodeInfo)

type MockResponder

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

MockResponder provides a configurable mock implementation of the control plane responder. It tracks requests received and provides configurable responses for testing.

func NewMockResponder

func NewMockResponder(ctx context.Context, conn *nats.Conn, behavior *MockResponderBehavior) (*MockResponder, error)

NewMockResponder creates a new mock responder with the given behavior. If behavior is nil, default success responses are used.

func (*MockResponder) Behaviour

func (m *MockResponder) Behaviour() *MockResponderBehavior

Behaviour returns the behavior configuration

func (*MockResponder) Close

func (m *MockResponder) Close(ctx context.Context) error

Close shuts down the responder

func (*MockResponder) GetHandshakes

func (m *MockResponder) GetHandshakes() []messages.HandshakeRequest

GetHandshakes returns a copy of all handshake requests received

func (*MockResponder) GetHeartbeats

func (m *MockResponder) GetHeartbeats() []messages.HeartbeatRequest

GetHeartbeats returns a copy of all heartbeat requests received

func (*MockResponder) GetNodeInfos

func (m *MockResponder) GetNodeInfos() []messages.UpdateNodeInfoRequest

GetNodeInfos returns a copy of all node info update requests received

func (*MockResponder) GetShutdowns

func (m *MockResponder) GetShutdowns() []messages.ShutdownNoticeRequest

type MockResponderBehavior

type MockResponderBehavior struct {
	// HandshakeResponse controls behavior for handshake requests
	HandshakeResponse struct {
		Error    error                      // Error to return, if any
		Response messages.HandshakeResponse // Response to return if no error
	}

	// HeartbeatResponse controls behavior for heartbeat requests
	HeartbeatResponse struct {
		Error    error                      // Error to return, if any
		Response messages.HeartbeatResponse // Response to return if no error
	}

	// NodeInfoResponse controls behavior for node info update requests
	NodeInfoResponse struct {
		Error    error                           // Error to return, if any
		Response messages.UpdateNodeInfoResponse // Response to return if no error
	}

	// ShutdownResponse controls behavior for shutdown notifications
	ShutdownResponse struct {
		Error    error                           // Error to return, if any
		Response messages.ShutdownNoticeResponse // Response to return if no error
	}

	// Callbacks for request inspection
	OnHandshake func(messages.HandshakeRequest)      // Called when handshake received
	OnHeartbeat func(messages.HeartbeatRequest)      // Called when heartbeat received
	OnNodeInfo  func(messages.UpdateNodeInfoRequest) // Called when node info update received
	OnShutdown  func(messages.ShutdownNoticeRequest)
}

MockResponderBehavior configures how the mock responder handles different request types. It allows customizing responses and errors for testing different scenarios.

Jump to

Keyboard shortcuts

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