/psqldocker

🚢 Go package providing lifecycle management for PostgreSQL Docker instances.

Primary LanguageGoMIT LicenseMIT

adrianbrad psqldocker

🚢 psqldocker

powered by ory/dockertest.

made-with-Go GitHub go.mod Go version of a Go module GoDoc reference example

CodeFactor Go Report Card lint-test codecov


Go package providing lifecycle management for PostgreSQL Docker instances.

Leverage Docker to run unit and integration tests against a real PostgreSQL database.

Usage

The following code shows how to start and stop a PostgreSQL container in a TestMain function.

func TestMain(m *testing.M) {
    c, err := psqldocker.NewContainer(
        "user",
        "password",
        "dbName",
        psqldocker.WithContainerName("test"),
        psqldocker.WithSql( //initialize with a schema
        "CREATE TABLE users(user_id UUID PRIMARY KEY);",
        ),
        ...
    )
    if err != nil {
        fmt.Printf("new container: %s", err)
        return
    }
	
    var ret int
	
    defer func() {
        _ = c.Close()
		
        os.Exit(ret)
    }   
	
    ret = m.Run()
}