testcontainerpostgres

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: Apache-2.0, Unlicense Imports: 4 Imported by: 0

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

Documentation

Overview

Package testcontainerpostgres provides an easy way to start a postgres testcontainer using docker

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, tag string, opts ...Option) (testcontainers.Container, string, error)

New setup a postgres testcontainer

func Terminate

func Terminate(ctx context.Context, c testcontainers.Container)

Terminate terminates the container in a defer friendly way

Types

type Option added in v0.1.0

type Option func(testcontainers.ContainerRequest) testcontainers.ContainerRequest

func WithAuth added in v0.1.0

func WithAuth(user, pass string) Option

WithAuth adds a username and password to the container request

func WithDb added in v0.1.0

func WithDb(db string) Option

WithDb adds a database name to the container request

func WithEnv added in v0.1.0

func WithEnv(env map[string]string) Option

WithEnv replaces the environment variables of the container request

func WithInit added in v0.1.0

func WithInit(init string) Option

WithInit adds a path to a folder containing sql files to be executed on startup

Jump to

Keyboard shortcuts

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