searcherside/internal/db/dbtest/postgres.go
Peter Kurfer 9ea9a8f658
Some checks failed
Go build / build (push) Failing after 1m58s
feat: continue basic setup
- setup ent scheme
- add command to create users
- document API
- add helpers to create migrations
- add command to run migrations
- add basic compose file
2024-06-19 21:19:37 +02:00

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
}
}