Documentation
¶
Overview ¶
Package driver provides low-level wire protocol driver for testing.
Index ¶
- type Conn
- func (c *Conn) AuthInfo() (*url.Userinfo, string)
- func (c *Conn) Authenticate(ctx context.Context) error
- func (c *Conn) Close() error
- func (c *Conn) Read() (*wire.MsgHeader, wire.MsgBody, error)
- func (c *Conn) Request(ctx context.Context, header *wire.MsgHeader, body wire.MsgBody) (*wire.MsgHeader, wire.MsgBody, error)
- func (c *Conn) Write(header *wire.MsgHeader, body wire.MsgBody) error
- func (c *Conn) WriteRaw(b []byte) error
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 ¶
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
AuthInfo returns the authentication credentials and mechanism extracted from the MongoDB URI.
func (*Conn) Authenticate ¶ added in v1.23.0
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) 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.