Documentation
¶
Index ¶
- func WithRootUser(username, password string) options.Option
- type Container
- func Run(opts ...options.Option) (*Container, error)
- func RunTest(t *testing.T, opts ...options.Option) (con *Container, err error)
- func RunTestWithContext(t *testing.T, ctx context.Context, opts ...options.Option) (con *Container, err error)
- func RunWithContext(ctx context.Context, opts ...options.Option) (con *Container, err error)
- func (c *Container) NewClient() (*mongo.Client, error)
- func (c *Container) NewClientWithContext(ctx context.Context) (*mongo.Client, error)
- func (c *Container) NewDatabase(name string, opts ...*options.DatabaseOptions) (*mongo.Database, error)
- func (c *Container) NewDatabaseWithContext(ctx context.Context, name string, opts ...*options.DatabaseOptions) (*mongo.Database, error)
- func (c *Container) NewTestClient(t *testing.T) (*mongo.Client, error)
- func (c *Container) NewTestClientWithContext(t *testing.T, ctx context.Context) (*mongo.Client, error)
- func (c *Container) NewTestDatabase(t testing.TB, opts ...*options.DatabaseOptions) (*mongo.Database, error)
- func (c *Container) NewTestDatabaseWithContext(t testing.TB, ctx context.Context, opts ...*options.DatabaseOptions) (*mongo.Database, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithRootUser ¶
WithRootUser sets MONGO_INITDB_ROOT_USERNAME & MONGO_INITDB_ROOT_PASSWORD to the given username & password.
Types ¶
type Container ¶
func Run ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.