Peter Kurfer
9ea9a8f658
Some checks failed
Go build / build (push) Failing after 1m58s
- setup ent scheme - add command to create users - document API - add helpers to create migrations - add command to run migrations - add basic compose file
39 lines
976 B
Go
39 lines
976 B
Go
package dbtest
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/testcontainers/testcontainers-go"
|
|
tcpostgres "github.com/testcontainers/testcontainers-go/modules/postgres"
|
|
"github.com/testcontainers/testcontainers-go/wait"
|
|
)
|
|
|
|
func TestPostgresDatabase(ctx context.Context) (string, DbCloser, error) {
|
|
container, err := tcpostgres.RunContainer(
|
|
ctx,
|
|
withImage("docker.io/postgres:16-alpine"),
|
|
tcpostgres.WithDatabase("gophershare"),
|
|
tcpostgres.WithUsername("postgres"),
|
|
tcpostgres.WithPassword("postgres"),
|
|
testcontainers.WithWaitStrategy(
|
|
wait.ForListeningPort("5432/tcp"),
|
|
),
|
|
)
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
connString, err := container.ConnectionString(ctx, "sslmode=disable")
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
return connString, CloserFunc(container.Terminate), nil
|
|
}
|
|
|
|
func withImage(image string) testcontainers.CustomizeRequestOption {
|
|
return func(req *testcontainers.GenericContainerRequest) error {
|
|
req.Image = image
|
|
return nil
|
|
}
|
|
}
|