xmongo

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReplicaSetName = "rs0"
)

Variables

This section is empty.

Functions

func ConvertMongoError

func ConvertMongoError(err error, entity string, keyFmt string, args ...interface{}) error

func ConvertSortOptionsToMongo

func ConvertSortOptionsToMongo(defaultField string, defaultDirection xpaging.SortDirection, options xpaging.SortOptions) bson.D

func CreateIndexes

func CreateIndexes(logger xlogger.Logger, collection *mongo.Collection, models ...mongo.IndexModel)

CreateIndexes creates one or more indexes in the provided collection reporting the result in the log

Types

type Container added in v0.29.0

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

Container is a wrapper around dockertest.Resource to allow run commands against an existent container

func (*Container) Close added in v0.29.0

func (c *Container) Close()

func (*Container) TailLogs added in v0.29.0

func (c *Container) TailLogs(ctx context.Context, wr io.Writer, follow bool) error

TailLogs tails the logs of the container.

type MongoInMemory

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

MongoInMemory allows to start a MongoDB instance in memory to run tests against To use it, create a new instance of MongoInMemory and call Connect() before running your tests and call Disconnect() after your tests are done. The client to connect to MongoDB can be retrieved by calling Client().

func (*MongoInMemory) Client

func (m *MongoInMemory) Client() *mongo.Client

func (*MongoInMemory) Connect

func (m *MongoInMemory) Connect(options ...Option)

Connect starts a MongoDB instance in memory and connects to it. You can pass options to configure the instance. The instance will be stopped and removed when Disconnect() is called. If you want to see the logs of the instance, pass the WithLogContainer() option. If you want to use a replica set, pass the WithReplicaSet() option. If you want to see the more logs, pass the WithDebug() option.

func (*MongoInMemory) Disconnect

func (m *MongoInMemory) Disconnect()

Disconnect stops and removes the container

type Option added in v0.25.1

type Option func(*MongoInMemory)

func WithContainerLogs added in v0.29.0

func WithContainerLogs() Option

WithContainerLogs enables logging of the container stdout and stderr

func WithDebug added in v0.29.0

func WithDebug() Option

WithDebug enables debug mode. More logs will be printed

func WithReplicaSet added in v0.29.0

func WithReplicaSet() Option

WithReplicaSet enables replica set in the mongo database. This is useful when you want to test transactions.

Jump to

Keyboard shortcuts

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