Documentation ¶
Index ¶
- Constants
- func ConvertMongoError(err error, entity string, keyFmt string, args ...interface{}) error
- func ConvertSortOptionsToMongo(defaultField string, defaultDirection xpaging.SortDirection, ...) bson.D
- func CreateIndexes(logger xlogger.Logger, collection *mongo.Collection, ...)
- type Container
- type MongoInMemory
- type Option
Constants ¶
const (
ReplicaSetName = "rs0"
)
Variables ¶
This section is empty.
Functions ¶
func ConvertMongoError ¶
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
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.