refactor(backend): standardize errors and simplify configuration and test setup
This commit is contained in:
1 parent
1535c19b8c
commit
138666a7bb
92 files changed
+3994
-210
No files matched your search
@@ -5,46 +5,13 @@ 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)
|
||||
env := bootstrap(t, postgresService)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), readinessTimeout)
|
||||
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 {
|
||||
if err := env.Postgres.Check(ctx); err != nil {
|
||||
t.Fatalf("PostgreSQL health query failed: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user