testmongo

package
v0.0.0-...-96860c4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithRootUser

func WithRootUser(username, password string) options.Option

WithRootUser sets MONGO_INITDB_ROOT_USERNAME & MONGO_INITDB_ROOT_PASSWORD to the given username & password.

Types

type Container

type Container struct {
	tc.Container
	ConnectionString string
}

func Run

func Run(opts ...options.Option) (*Container, error)

Run creates and starts a docker Container with the `mongo` image. Defaults to `mongo:latest` if no option sets image tag. A default context is used with a timeout of two minutes. To customize use RunWithContext.

func RunTest

func RunTest(t *testing.T, opts ...options.Option) (con *Container, err error)

RunTest creates and starts a docker Container with the `mongo` image. Defaults to `mongo:latest` if no option sets image tag. The Container is automatically terminated after the test is finished. A default context is used with a timeout of two minutes. To customize use RunTestWithContext.

func RunTestWithContext

func RunTestWithContext(t *testing.T, ctx context.Context, opts ...options.Option) (con *Container, err error)

RunTestWithContext creates and starts a docker Container with the `mongo` image. Defaults to `mongo:latest` if no option sets image tag. A context can be provided to configure things such as timeout. The Container is automatically terminated after the test is finished.

func RunWithContext

func RunWithContext(ctx context.Context, opts ...options.Option) (con *Container, err error)

RunWithContext creates and starts a docker Container with the `mongo` image. Defaults to `mongo:latest` if no option sets image tag. A context can be provided to configure things such as timeout.

func (*Container) NewClient

func (c *Container) NewClient() (*mongo.Client, error)

NewClient creates a new mongo client using the connection string of the Container. The connection is tested once before returning the new client.

func (*Container) NewClientWithContext

func (c *Container) NewClientWithContext(ctx context.Context) (*mongo.Client, error)

NewClientWithContext creates a new mongo client using the connection string of the Container. The connection is tested once before returning the new client. NewClientWithContext exists to allow you to customize the connection process, e.g., apply timeout.

func (*Container) NewDatabase

func (c *Container) NewDatabase(name string, opts ...*options.DatabaseOptions) (*mongo.Database, error)

NewDatabase creates a new mongo client then a new database with then given name and options.

func (*Container) NewDatabaseWithContext

func (c *Container) NewDatabaseWithContext(ctx context.Context, name string, opts ...*options.DatabaseOptions) (*mongo.Database, error)

NewDatabaseWithContext creates a new mongo.Database with then given name and options. NewDatabaseWithContext exists to allow you to customize the connection process, e.g., apply timeout.

func (*Container) NewTestClient

func (c *Container) NewTestClient(t *testing.T) (*mongo.Client, error)

NewTestClient creates a mongo.Client for testing purposes. The mongo.Client will be disconnected automatically after the test finishes. Note: A default context is used with a timeout of two minutes.

func (*Container) NewTestClientWithContext

func (c *Container) NewTestClientWithContext(t *testing.T, ctx context.Context) (*mongo.Client, error)

NewTestClientWithContext creates a mongo.Client for testing purposes. The mongo.Client will be disconnected automatically after the test finishes.

func (*Container) NewTestDatabase

func (c *Container) NewTestDatabase(t testing.TB, opts ...*options.DatabaseOptions) (*mongo.Database, error)

NewTestDatabase creates a new Database with a random name within the Container. The database is automatically dropped after to test it finished. Note: A default context is used with a timeout of two minutes.

func (*Container) NewTestDatabaseWithContext

func (c *Container) NewTestDatabaseWithContext(t testing.TB, ctx context.Context, opts ...*options.DatabaseOptions) (*mongo.Database, error)

NewTestDatabaseWithContext creates a new mongo.Database with a random name within the Container. The database will be named randomly. The database is automatically dropped and the underlying mongo.Client will be disconnected after to test it finished.

Jump to

Keyboard shortcuts

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