initial commit
This commit is contained in:
commit
88c14b627e
224 files changed
+17204
No files matched your search
@@ -0,0 +1,50 @@
|
||||
//go:build integration
|
||||
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||
|
||||
"lincodex/backend/config"
|
||||
postgresadapter "lincodex/backend/internal/adapter/secondary/postgres"
|
||||
)
|
||||
|
||||
func TestPostgresHealthQueryAgainstContainer(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
|
||||
defer cancel()
|
||||
container, err := postgres.Run(ctx, "postgres:alpine",
|
||||
postgres.WithDatabase("health"),
|
||||
postgres.WithUsername("health"),
|
||||
postgres.WithPassword("health"),
|
||||
postgres.BasicWaitStrategies(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("start PostgreSQL container: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := testcontainers.TerminateContainer(container); err != nil {
|
||||
t.Errorf("terminate PostgreSQL container: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
databaseURL, err := container.ConnectionString(ctx, "sslmode=disable")
|
||||
if err != nil {
|
||||
t.Fatalf("get PostgreSQL connection string: %v", err)
|
||||
}
|
||||
checker, closePool, err := postgresadapter.NewHealthChecker(ctx, config.Config{DatabaseURL: databaseURL})
|
||||
if err != nil {
|
||||
t.Fatalf("create PostgreSQL health checker: %v", err)
|
||||
}
|
||||
defer closePool()
|
||||
|
||||
checkContext, checkCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer checkCancel()
|
||||
if err := checker.Check(checkContext); err != nil {
|
||||
t.Fatalf("PostgreSQL health query failed: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user