drivertest

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package drivertest is intended for internal use only. It is made available to facilitate use cases that require access to internal MongoDB driver functionality and state. The API of this package is not stable and there is no backward compatibility guarantee.

WARNING: THIS PACKAGE IS EXPERIMENTAL AND MAY BE MODIFIED OR REMOVED WITHOUT NOTICE! USE WITH EXTREME CAUTION!

Index

Constants

This section is empty.

Variables

View Source
var (

	// MockDescription is the server description used for the mock deployment. Each mocked connection returns this
	// value from its Description method.
	MockDescription = description.Server{
		CanonicalAddr:         serverAddress,
		MaxDocumentSize:       maxDocumentSize,
		MaxMessageSize:        maxMessageSize,
		MaxBatchCount:         maxBatchCount,
		SessionTimeoutMinutes: &sessionTimeoutMinutes,
		Kind:                  description.ServerKindRSPrimary,
		WireVersion: &description.VersionRange{
			Max: driverutil.MaxWireVersion,
		},
	}
)

Functions

func GetCommandFromMsgWireMessage

func GetCommandFromMsgWireMessage(wm []byte) (bsoncore.Document, error)

GetCommandFromMsgWireMessage returns the command document sent in an OP_MSG wire message.

func GetCommandFromQueryWireMessage

func GetCommandFromQueryWireMessage(wm []byte) (bsoncore.Document, error)

GetCommandFromQueryWireMessage returns the command sent in an OP_QUERY wire message.

func MakeReply

func MakeReply(doc bsoncore.Document) []byte

MakeReply creates an OP_REPLY wiremessage from a BSON document

Types

type ChannelConn

type ChannelConn struct {
	WriteErr error
	Written  chan []byte
	ReadResp chan []byte
	ReadErr  chan error
	Desc     description.Server
}

ChannelConn implements the driver.Connection interface by reading and writing wire messages to a channel

func (*ChannelConn) Address

func (c *ChannelConn) Address() address.Address

Address implements the driver.Connection interface.

func (*ChannelConn) Close

func (c *ChannelConn) Close() error

Close implements the driver.Connection interface.

func (*ChannelConn) Description

func (c *ChannelConn) Description() description.Server

Description implements the driver.Connection interface.

func (*ChannelConn) DriverConnectionID

func (c *ChannelConn) DriverConnectionID() int64

DriverConnectionID implements the driver.Connection interface.

func (*ChannelConn) ID

func (c *ChannelConn) ID() string

ID implements the driver.Connection interface.

func (*ChannelConn) OIDCTokenGenID

func (c *ChannelConn) OIDCTokenGenID() uint64

OIDCTokenGenID implements the driver.Connection interface by returning the OIDCToken generation (which is always 0)

func (*ChannelConn) Read

func (c *ChannelConn) Read(ctx context.Context) ([]byte, error)

ReadWireMessage implements the driver.Connection interface.

func (*ChannelConn) ServerConnectionID

func (c *ChannelConn) ServerConnectionID() *int64

ServerConnectionID implements the driver.Connection interface.

func (*ChannelConn) SetOIDCTokenGenID

func (c *ChannelConn) SetOIDCTokenGenID(uint64)

SetOIDCTokenGenID implements the driver.Connection interface by setting the OIDCToken generation (which is always 0)

func (*ChannelConn) Stale

func (c *ChannelConn) Stale() bool

Stale implements the driver.Connection interface.

func (*ChannelConn) Write

func (c *ChannelConn) Write(ctx context.Context, wm []byte) error

WriteWireMessage implements the driver.Connection interface.

type ChannelNetConn

type ChannelNetConn struct {
	WriteErr error
	Written  chan []byte
	ReadResp chan []byte
	ReadErr  chan error
}

ChannelNetConn implements the net.Conn interface by reading and writing wire messages to a channel.

func (*ChannelNetConn) AddResponse

func (c *ChannelNetConn) AddResponse(resp []byte) error

AddResponse adds a response to the connection.

func (*ChannelNetConn) Close

func (c *ChannelNetConn) Close() error

Close closes the connection.

func (*ChannelNetConn) GetWrittenMessage

func (c *ChannelNetConn) GetWrittenMessage() []byte

GetWrittenMessage gets the last wire message written to the connection

func (*ChannelNetConn) LocalAddr

func (c *ChannelNetConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*ChannelNetConn) Read

func (c *ChannelNetConn) Read(b []byte) (int, error)

Read reads data from the connection

func (*ChannelNetConn) RemoteAddr

func (c *ChannelNetConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*ChannelNetConn) SetDeadline

func (c *ChannelNetConn) SetDeadline(_ time.Time) error

SetDeadline sets the read and write deadlines associated with the connection.

func (*ChannelNetConn) SetReadDeadline

func (c *ChannelNetConn) SetReadDeadline(_ time.Time) error

SetReadDeadline sets the read and write deadlines associated with the connection.

func (*ChannelNetConn) SetWriteDeadline

func (c *ChannelNetConn) SetWriteDeadline(_ time.Time) error

SetWriteDeadline sets the read and write deadlines associated with the connection.

func (*ChannelNetConn) Write

func (c *ChannelNetConn) Write(b []byte) (int, error)

Write writes data to the connection.

type MockDeployment

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

MockDeployment wraps a connection and implements the driver.Deployment interface.

func NewMockDeployment

func NewMockDeployment(responses ...bson.D) *MockDeployment

NewMockDeployment returns a mock driver.Deployment that responds with OP_MSG wire messages. However, for most use cases, we suggest testing with an actual database.

func (*MockDeployment) AddResponses

func (md *MockDeployment) AddResponses(responses ...bson.D)

AddResponses adds responses to this mock deployment.

func (*MockDeployment) ClearResponses

func (md *MockDeployment) ClearResponses()

ClearResponses clears all remaining responses in this mock deployment.

func (*MockDeployment) Connect

func (md *MockDeployment) Connect() error

Connect is a no-op method which implements the driver.Connector interface.

func (*MockDeployment) Connection

func (md *MockDeployment) Connection(context.Context) (*mnet.Connection, error)

Connection implements the driver.Server interface.

func (*MockDeployment) Disconnect

func (md *MockDeployment) Disconnect(context.Context) error

Disconnect is a no-op method which implements the driver.Disconnector interface {

func (*MockDeployment) GetServerSelectionTimeout

func (*MockDeployment) GetServerSelectionTimeout() time.Duration

GetServerSelectionTimeout returns zero as a server selection timeout is not applicable for mock deployments.

func (*MockDeployment) Kind

Kind implements the Deployment interface. It always returns description.TopologyKindSingle.

func (*MockDeployment) RTTMonitor

func (md *MockDeployment) RTTMonitor() driver.RTTMonitor

RTTMonitor implements the driver.Server interface.

func (*MockDeployment) SelectServer

SelectServer implements the Deployment interface. This method does not use the description.SelectedServer provided and instead returns itself. The Connections returned from the Connection method have a no-op Close method.

func (*MockDeployment) Subscribe

func (md *MockDeployment) Subscribe() (*driver.Subscription, error)

Subscribe returns a subscription from which new topology descriptions can be retrieved. Subscribe implements the driver.Subscriber interface.

func (*MockDeployment) Unsubscribe

func (md *MockDeployment) Unsubscribe(*driver.Subscription) error

Unsubscribe is a no-op method which implements the driver.Subscriber interface.

Jump to

Keyboard shortcuts

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