.PHONY: pip_dev dev lint test test_unit pip_test_integration test_integration clean clean_test_integration docker_unit_lint up_dev down_dev up_deploy down_deploy
.PHONY: ci_unit_lint_clean ci_unit_lint down_docker_compose

test: env
	env/bin/py.test tests_backend/unit/

test_unit: env
	env/bin/py.test \
		--cov src/backend tests_backend/unit/ \
		--cov-report xml \
		--junitxml=pyunit.xml

tests/integration/env pip_test_integration:
	python3.12 -m venv tests_backend/integration/env
	tests/integration/env/bin/pip3.12 install --upgrade pip
	tests/integration/env/bin/pip3.12 install -r requirements-test.txt

test_integration: tests/integration/env
	tests/integration/env/bin/py.test tests_backend/integration

clean:
	rm -rf env

clean_test_integration:
	rm -rf tests_backend/integration/env

up_dev:
	docker compose up \
		--detach \
		--remove-orphans \
		yt_audits-dev

down_dev:
	docker compose down yt_audits-dev

up_deploy:
	docker compose build \
		--no-cache \
		yt_audits-deploy
	docker compose up \
		--detach \
		--remove-orphans \
		yt_audits-deploy

down_deploy:
	docker compose down yt_audits-deploy

docker_unit_lint:
	docker compose up \
		--build \
		--exit-code-from unit-lint \
		--abort-on-container-exit \
		--remove-orphans \
		unit-lint

down_docker_compose:
	docker compose down --remove-orphans
	docker compose down -v

ci_unit_lint: ci_unit_lint_clean
	mkdir -p build
	chmod a+w build
	make docker_unit_lint

ci_unit_lint_clean: down_docker_compose
	rm -rf build

docker_test_integration:
	docker compose up \
		--build \
		--exit-code-from test-integration \
		--abort-on-container-exit \
		--remove-orphans \
		test-integration

ci_test_integration: docker_test_integration
