driver

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package driver provides low-level wire protocol driver for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn represents a single connection.

It is not safe for concurrent use.

Logger is used only with debug level.

func Connect

func Connect(ctx context.Context, uri string, l *slog.Logger) (*Conn, error)

Connect creates a new non-authenticated connection for the given MongoDB URI and logger.

Context can be used to cancel the connection attempt. Canceling the context after the connection is established has no effect.

Authentication credentials and mechanism can be set in the URI. They are not used by this function, but available to [Authenticate] and via [AuthInfo].

func (*Conn) AuthInfo added in v1.23.0

func (c *Conn) AuthInfo() (*url.Userinfo, string)

AuthInfo returns the authentication credentials and mechanism extracted from the MongoDB URI.

func (*Conn) Authenticate added in v1.23.0

func (c *Conn) Authenticate(ctx context.Context) error

Authenticate attempts to authenticate the connection.

This method is a shortcut for code that primary does not test authentication itself, but accesses MongoDB-compatible system that requires authentication. Code that tests various authentication scenarios should use [Request], [Write], or [WriteRaw] directly.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Read

func (c *Conn) Read() (*wire.MsgHeader, wire.MsgBody, error)

Read reads the next message from the connection.

func (*Conn) Request

func (c *Conn) Request(ctx context.Context, header *wire.MsgHeader, body wire.MsgBody) (*wire.MsgHeader, wire.MsgBody, error)

Request sends the given request to the connection and returns the response. If header MessageLength or RequestID is not specified, it assigns the proper values. For header.OpCode the wire.OpCodeMsg is used as default.

It returns errors only for request/response parsing issues, or connection issues. All of the driver level errors are stored inside response.

func (*Conn) Write

func (c *Conn) Write(header *wire.MsgHeader, body wire.MsgBody) error

Write writes the given message to the connection.

func (*Conn) WriteRaw

func (c *Conn) WriteRaw(b []byte) error

WriteRaw writes the given raw bytes to the connection.

Jump to

Keyboard shortcuts

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