Categorygithub.com/thlib/testcontainermongo
modulepackage
0.1.0
Repository: https://github.com/thlib/testcontainermongo.git
Documentation: pkg.go.dev

# README

Mongo testcontainer

A mongo docker testcontainer for go

Example usage:

import (
	"context"
	"path/filepath"
	"regexp"
	"testing"

	testmongo "github.com/thlib/testcontainermongo"
)
initPath, err := filepath.Abs("./initdb")
if err != nil {
    log.Fatalf("%v", err)
}
ctx := context.Background()
c, conn, err := testmongo.New(ctx, "latest",
    testmongo.WithInit(initdb),
    testmongo.WithDb("test_db"),
    testmongo.WithAuth("root", "example"),
)
defer testmongo.Terminate(ctx, container)

fmt.Println(conn)
// Output: mongodb://root:example@localhost:49156/test_db

Run tests

go test

# Functions

New setup a mongo testcontainer.
Terminate terminates the container in a defer friendly way.
WithAuth adds a username and password to the container request.
WithDb adds a database name to the container request.
WithEnv replaces the environment variables of the container request.
WithInit adds a path to a folder containing sql files to be executed on startup.

# Type aliases

No description provided by the author