Proper integration tests
This commit is contained in:
61
Makefile
61
Makefile
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: all build test test-unit test-integration lint coverage clean install help docker-up docker-down docker-test docker-test-integration release release-version
|
.PHONY: all build test test-unit test-integration lint coverage clean install help docker-up docker-down docker-test docker-test-integration start stop release release-version
|
||||||
|
|
||||||
# Binary name
|
# Binary name
|
||||||
BINARY_NAME=relspec
|
BINARY_NAME=relspec
|
||||||
@@ -14,6 +14,26 @@ GOGET=$(GOCMD) get
|
|||||||
GOMOD=$(GOCMD) mod
|
GOMOD=$(GOCMD) mod
|
||||||
GOCLEAN=$(GOCMD) clean
|
GOCLEAN=$(GOCMD) clean
|
||||||
|
|
||||||
|
# Auto-detect container runtime (Docker or Podman)
|
||||||
|
CONTAINER_RUNTIME := $(shell \
|
||||||
|
if command -v podman > /dev/null 2>&1; then \
|
||||||
|
echo "podman"; \
|
||||||
|
elif command -v docker > /dev/null 2>&1; then \
|
||||||
|
echo "docker"; \
|
||||||
|
else \
|
||||||
|
echo "none"; \
|
||||||
|
fi)
|
||||||
|
|
||||||
|
# Detect compose command
|
||||||
|
COMPOSE_CMD := $(shell \
|
||||||
|
if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \
|
||||||
|
echo "podman-compose"; \
|
||||||
|
elif command -v docker-compose > /dev/null 2>&1; then \
|
||||||
|
echo "docker-compose"; \
|
||||||
|
else \
|
||||||
|
echo "docker compose"; \
|
||||||
|
fi)
|
||||||
|
|
||||||
all: lint test build ## Run linting, tests, and build
|
all: lint test build ## Run linting, tests, and build
|
||||||
|
|
||||||
build: ## Build the binary
|
build: ## Build the binary
|
||||||
@@ -81,12 +101,26 @@ deps: ## Download dependencies
|
|||||||
$(GOMOD) tidy
|
$(GOMOD) tidy
|
||||||
@echo "Dependencies updated"
|
@echo "Dependencies updated"
|
||||||
|
|
||||||
|
start: docker-up ## Alias for docker-up (start PostgreSQL test database)
|
||||||
|
|
||||||
|
stop: docker-down ## Alias for docker-down (stop PostgreSQL test database)
|
||||||
|
|
||||||
docker-up: ## Start PostgreSQL test database
|
docker-up: ## Start PostgreSQL test database
|
||||||
@echo "Starting PostgreSQL test database..."
|
@echo "Starting PostgreSQL test database (using $(CONTAINER_RUNTIME))..."
|
||||||
@if command -v docker-compose > /dev/null 2>&1; then \
|
@if [ "$(CONTAINER_RUNTIME)" = "none" ]; then \
|
||||||
docker-compose up -d postgres; \
|
echo "Error: Neither Docker nor Podman is installed"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \
|
||||||
|
podman run -d --name relspec-test-postgres \
|
||||||
|
-e POSTGRES_USER=relspec \
|
||||||
|
-e POSTGRES_PASSWORD=relspec_test_password \
|
||||||
|
-e POSTGRES_DB=relspec_test \
|
||||||
|
-p 5433:5432 \
|
||||||
|
-v ./tests/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:Z \
|
||||||
|
postgres:16-alpine 2>/dev/null || echo "Container already running"; \
|
||||||
else \
|
else \
|
||||||
docker compose up -d postgres; \
|
$(COMPOSE_CMD) up -d postgres; \
|
||||||
fi
|
fi
|
||||||
@echo "Waiting for PostgreSQL to be ready..."
|
@echo "Waiting for PostgreSQL to be ready..."
|
||||||
@sleep 3
|
@sleep 3
|
||||||
@@ -94,16 +128,21 @@ docker-up: ## Start PostgreSQL test database
|
|||||||
@echo "Connection: postgres://relspec:relspec_test_password@localhost:5433/relspec_test"
|
@echo "Connection: postgres://relspec:relspec_test_password@localhost:5433/relspec_test"
|
||||||
|
|
||||||
docker-down: ## Stop PostgreSQL test database
|
docker-down: ## Stop PostgreSQL test database
|
||||||
@echo "Stopping PostgreSQL test database..."
|
@echo "Stopping PostgreSQL test database (using $(CONTAINER_RUNTIME))..."
|
||||||
@if command -v docker-compose > /dev/null 2>&1; then \
|
@if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \
|
||||||
docker-compose down; \
|
podman stop relspec-test-postgres 2>/dev/null || true; \
|
||||||
|
podman rm relspec-test-postgres 2>/dev/null || true; \
|
||||||
else \
|
else \
|
||||||
docker compose down; \
|
$(COMPOSE_CMD) down; \
|
||||||
fi
|
fi
|
||||||
@echo "PostgreSQL stopped"
|
@echo "PostgreSQL stopped"
|
||||||
|
|
||||||
docker-test: ## Run PostgreSQL integration tests with Docker
|
docker-test: ## Run PostgreSQL integration tests with Docker/Podman
|
||||||
@./tests/postgres/run_tests.sh
|
@if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \
|
||||||
|
./tests/postgres/run_tests_podman.sh; \
|
||||||
|
else \
|
||||||
|
./tests/postgres/run_tests.sh; \
|
||||||
|
fi
|
||||||
|
|
||||||
docker-test-integration: docker-up ## Start DB and run integration tests
|
docker-test-integration: docker-up ## Start DB and run integration tests
|
||||||
@echo "Running integration tests..."
|
@echo "Running integration tests..."
|
||||||
|
|||||||
Reference in New Issue
Block a user