powered by ory/dockertest
.
Go package providing lifecycle management for PostgreSQL Docker instances.
Leverage Docker to run unit and integration tests against a real PostgreSQL database.
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()
}