From 9e55e65ac5eb6ff645880ee253a33f6ab138b615 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 14 Aug 2025 11:54:52 -0600 Subject: Fix the broken build by running pg as a separate container. Improve shell scripts and remove /sparkles/restore endpoint - Add error handling and debugging to shell scripts with `set -e` and `DEBUG` flag - Ensure scripts run from project root with `cd "$(dirname "$0")/.."` - Remove `/sparkles/restore` endpoint from public routes and Envoy config - Add Postgres test container support for integration tests - Update CI configuration with newer Runway version and improved test setup - Simplify Makefile by removing redundant commands ------- :robot: Commit message generated by GitLab Duo --- test/integration/container.go | 16 ++++++++++++++++ test/integration/container_test.go | 26 ++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/integration/container.go b/test/integration/container.go index 67d7603..c95bdfd 100644 --- a/test/integration/container.go +++ b/test/integration/container.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/log" + "github.com/testcontainers/testcontainers-go/modules/postgres" "github.com/testcontainers/testcontainers-go/wait" "github.com/xlgmokha/x/pkg/env" ) @@ -34,3 +35,18 @@ func NewContainer(t *testing.T, ctx context.Context, envVars map[string]string) require.NoError(t, err) return container } + +func NewPgContainer(ctx context.Context, t *testing.T) *postgres.PostgresContainer { + container, err := postgres.Run(ctx, "postgres:17", + postgres.WithDatabase("sparkle_test"), + postgres.WithUsername("postgres"), + postgres.WithPassword("secret"), + testcontainers.WithLogConsumers(&Logger{TB: t}), + testcontainers.WithLogger(log.TestLogger(t)), + testcontainers.WithWaitStrategy( + wait.ForListeningPort("5432/tcp"), + ), + ) + require.NoError(t, err) + return container +} diff --git a/test/integration/container_test.go b/test/integration/container_test.go index a3e7974..4273eff 100644 --- a/test/integration/container_test.go +++ b/test/integration/container_test.go @@ -16,28 +16,38 @@ import ( "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web" ) -func environmentVariables(srv *web.OIDCServer) map[string]string { +func environmentVariables(srv *web.OIDCServer, databaseURL string) map[string]string { return map[string]string{ "APP_ENV": "test", + "AUTHZD_HOST": "", + "DATABASE_URL": databaseURL, "DEBUG": env.Fetch("DEBUG", ""), "HMAC_SESSION_SECRET": "secret", - "LOG_LEVEL": "debug", + "LOG_LEVEL": "warn", "OAUTH_CLIENT_ID": srv.MockOIDC.ClientID, "OAUTH_CLIENT_SECRET": srv.MockOIDC.ClientSecret, "OIDC_ISSUER": srv.Issuer(), - "ZED_ENDPOINT": ":50051", - "ZED_TOKEN": "secret", + "RUNWAY_PG_USER_POSTGRES_PASSWORD_SPARKLE": "secret", + "ZED_ENDPOINT": ":50051", + "ZED_TOKEN": "secret", } } func TestContainer(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - srv := web.NewOIDCServer(t) defer srv.Close() - container := NewContainer(t, ctx, environmentVariables(srv)) + ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) + defer cancel() + + pgContainer := NewPgContainer(ctx, t) + defer pgContainer.Terminate(ctx) + + databaseURL, err := pgContainer.ConnectionString(ctx, "sslmode=disable") + require.NoError(t, err) + + envVars := environmentVariables(srv, databaseURL) + container := NewContainer(t, ctx, envVars) defer testcontainers.TerminateContainer(container) require.True(t, container.IsRunning()) -- cgit v1.2.3