https://github.com/adrianbrad/psqldocker
🚢 Go package providing lifecycle management for PostgreSQL Docker instances.
https://github.com/adrianbrad/psqldocker
docker go postgresql
Last synced: 5 months ago
JSON representation
🚢 Go package providing lifecycle management for PostgreSQL Docker instances.
- Host: GitHub
- URL: https://github.com/adrianbrad/psqldocker
- Owner: adrianbrad
- License: mit
- Created: 2022-04-11T17:55:13.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-27T06:04:13.000Z (about 2 years ago)
- Last Synced: 2024-06-19T16:33:18.393Z (about 2 years ago)
- Topics: docker, go, postgresql
- Language: Go
- Homepage:
- Size: 178 KB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

# 🚢 psqldocker 
powered by [`ory/dockertest`](https://github.com/ory/dockertest).
[](https://github.com/adrianbrad/psqldocker)
[](https://pkg.go.dev/github.com/adrianbrad/psqldocker)
[](https://www.codefactor.io/repository/github/adrianbrad/psqldocker)
[](https://goreportcard.com/report/github.com/adrianbrad/psqldocker)
[](https://codecov.io/gh/adrianbrad/psqldocker)
[](https://github.com/adrianbrad/psqldocker/actions?query=workflow%3Alint-test)
[](https://github.com/adrianbrad/psqldocker/actions?query=workflow%3Agrype)
[](https://github.com/adrianbrad/psqldocker/actions?query=workflow%3ACodeQL)
[](https://github.com/adrianbrad/psqldocker/actions?query=workflow%3Agitleaks)
---
Go package providing lifecycle management for PostgreSQL Docker instances.
[Here](https://adrianbrad.medium.com/parallel-postgresql-tests-go-docker-6fb51c016796) is an article expanding on the usage of this package.
Leverage Docker to run unit and integration tests against a real PostgreSQL database.
### Usage
#### Recommended: In a TestXxx function
```go
package foo_test
import (
"testing"
"github.com/adrianbrad/psqldocker"
)
func TestXxx(t *testing.T) {
const schema = "CREATE TABLE users(user_id UUID PRIMARY KEY);"
c, err := psqldocker.NewContainer(
"user",
"password",
"dbName",
psqldocker.WithContainerName("test"),
// initialize with a schema
psqldocker.WithSql(schema),
// you can add other options here
)
if err != nil {
t.Fatalf("cannot start new psql container: %s\n", err)
}
t.Cleanup(func() {
err = c.Close()
if err != nil {
t.Logf("err while closing conainter: %w", err)
}
})
t.Run("Subtest", func(t *testing.T) {
// execute your test logic here
})
}
```
---
#### In a TestMain function
```go
package foo_test
import (
"log"
"testing"
"github.com/adrianbrad/psqldocker"
)
func TestMain(m *testing.M) {
const schema = "CREATE TABLE users(user_id UUID PRIMARY KEY);"
c, err := psqldocker.NewContainer(
"user",
"password",
"dbName",
psqldocker.WithContainerName("test"),
// initialize with a schema
psqldocker.WithSql(schema),
// you can add other options here
)
if err != nil {
log.Fatalf("cannot start new psql container: %s\n", err)
}
defer func() {
err = c.Close()
if err != nil {
log.Printf("err while closing conainter: %w", err)
}
}()
m.Run()
}
```