PYTHON ?= python3
BASE_URL ?= http://localhost:8080
CA_FILE ?=
ACTION_SCRIPT ?=
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)

.PHONY: help check validate test load test-persistence test-operational explain-history

help:
	@echo "check/validate: contract; test: API; test-persistence: restart; test-operational: failure/race/rollback; explain-history: 10k index plan"

check:
	$(PYTHON) scripts/check_contract.py

validate:
	$(PYTHON) scripts/validate_openapi.py

test:
	$(PYTHON) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)

load:
	$(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)

test-persistence:
ifeq ($(OS),Windows_NT)
	@if "$(ACTION_SCRIPT)"=="" (echo Set ACTION_SCRIPT to your implemented executable restart hook & exit /b 2)
else
	@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2)
endif
	$(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)

test-operational:
	$(PYTHON) tests/operational.py --base-url "$(BASE_URL)"

explain-history:
	$(PYTHON) scripts/explain_history.py
