xmongo

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 19 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 *zap.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

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

func (c *Container) Close()

func (*Container) TailLogs

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

type Option func(*MongoInMemory)

func WithContainerLogs

func WithContainerLogs() Option

WithContainerLogs enables logging of the container stdout and stderr

func WithDebug

func WithDebug() Option

WithDebug enables debug mode. More logs will be printed

func WithReplicaSet

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