fix(tests): update database connection strings for CI
Integration Tests / integration-test (push) Failing after 57s
Integration Tests / integration-test (push) Failing after 57s
* Use dynamic host and port for Postgres in tests * Add helper functions for test database host and port
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
.PHONY: all build clean test test-all test-ci test-integration-go test-unit-go test-connection schema-install broker-start broker-stop install deps docker-up docker-down docker-build release help
|
||||
.PHONY: all build clean test test-all test-ci test-integration-go test-unit-go test-connection generate-test-config schema-install broker-start broker-stop install deps docker-up docker-down docker-build release help
|
||||
|
||||
# Build variables
|
||||
BINARY_NAME=pgsql-broker
|
||||
@@ -30,6 +30,13 @@ COMPOSE_CMD := $(shell \
|
||||
|
||||
|
||||
|
||||
# Test database connection info. Override in CI to point at a dynamically
|
||||
# assigned Postgres (e.g. a services: block port), avoiding a fixed host port
|
||||
# that can collide with other jobs on a shared runner.
|
||||
TEST_DB_HOST ?= 127.0.0.1
|
||||
TEST_DB_PORT ?= 5433
|
||||
TEST_CONFIG := $(BIN_DIR)/broker.test.runtime.yaml
|
||||
|
||||
# Version information
|
||||
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
|
||||
@@ -68,12 +75,16 @@ test-all: test-teardown test-setup test-connection schema-install broker-start t
|
||||
test-ci: test-connection schema-install broker-start test-local-unit test-integration-go broker-stop ## Run all unit and integration tests against an externally-provided Postgres (CI services: block)
|
||||
|
||||
test-connection: deps ## Test database connection with retry
|
||||
@echo "Testing database connection..."
|
||||
@$(GO) test -v ./tests/integration/connection_test.go
|
||||
@echo "Testing database connection (host=$(TEST_DB_HOST) port=$(TEST_DB_PORT))..."
|
||||
@TEST_DB_HOST=$(TEST_DB_HOST) TEST_DB_PORT=$(TEST_DB_PORT) $(GO) test -v -run '^TestConnection$$' ./tests/integration/...
|
||||
|
||||
schema-install: build ## Install database schema using the broker CLI
|
||||
generate-test-config: ## (internal) render broker.test.yaml with TEST_DB_HOST/TEST_DB_PORT
|
||||
@mkdir -p $(BIN_DIR)
|
||||
@sed -e "s/^ host: .*/ host: $(TEST_DB_HOST)/" -e "s/^ port: .*/ port: $(TEST_DB_PORT)/" broker.test.yaml > $(TEST_CONFIG)
|
||||
|
||||
schema-install: build generate-test-config ## Install database schema using the broker CLI
|
||||
@echo "Installing database schema..."
|
||||
@$(BIN_DIR)/$(BINARY_NAME) install --config broker.test.yaml
|
||||
@$(BIN_DIR)/$(BINARY_NAME) install --config $(TEST_CONFIG)
|
||||
|
||||
test-setup: build ## Start test environment (docker-compose/podman-compose)
|
||||
@echo "Starting test environment (using $(COMPOSE_CMD))..."
|
||||
@@ -102,9 +113,9 @@ test-teardown: ## Stop test environment (docker-compose/podman-compose)
|
||||
fi
|
||||
@sleep 5 # Give the container runtime time to release resources
|
||||
|
||||
broker-start: build ## Start the broker in the background
|
||||
broker-start: build generate-test-config ## Start the broker in the background
|
||||
@echo "Starting broker..."
|
||||
@setsid $(BIN_DIR)/$(BINARY_NAME) start --config broker.test.yaml > broker.log 2>&1 < /dev/null & echo $$! > broker.pid
|
||||
@setsid $(BIN_DIR)/$(BINARY_NAME) start --config $(TEST_CONFIG) > broker.log 2>&1 < /dev/null & echo $$! > broker.pid
|
||||
@sleep 5 # Give the broker a moment to start
|
||||
|
||||
broker-stop: ## Stop the broker
|
||||
@@ -117,8 +128,8 @@ broker-stop: ## Stop the broker
|
||||
fi
|
||||
|
||||
test-integration-go: ## Run Go integration tests
|
||||
@echo "Running Go integration tests..."
|
||||
@$(GO) test -v ./tests/integration/...
|
||||
@echo "Running Go integration tests (host=$(TEST_DB_HOST) port=$(TEST_DB_PORT))..."
|
||||
@TEST_DB_HOST=$(TEST_DB_HOST) TEST_DB_PORT=$(TEST_DB_PORT) $(GO) test -v ./tests/integration/...
|
||||
|
||||
install: build ## Install the binary to GOPATH/bin
|
||||
@echo "Installing to GOPATH/bin..."
|
||||
|
||||
Reference in New Issue
Block a user