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

# README

Postgres testcontainer

A postgres docker testcontainer for go

Example usage:

initPath, err := filepath.Abs("./initdb")
if err != nil {
    log.Fatalf("%v", err)
}
ctx := context.Background()
postgresC, conn, err := testcontainerpostgres.New(ctx, "14.5-alpine",
    testcontainerpostgres.WithInit(initPath),
    testcontainerpostgres.WithDb("test_db"),
    testcontainerpostgres.WithAuth("postgres", "postgres"),
)
if err != nil {
    log.Fatalf("%v", err)
}
defer Terminate(ctx, postgresC)

fmt.Println(conn)
// Output: postgres://postgres:postgres@localhost:49156/test_db

Run tests

go test

# Functions

New setup a postgres 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