.PHONY: clean test lint docker_up docker_down docker_test

clean:
	rm -rf env .coverage .pytest_cache .cache coverage.xml pyunit.xml
	find . | grep -E '__pycache__|\.pyc|\.pyo$\' | xargs rm -rf

test:
	env/bin/python3.9 -m pytest tests

lint:
	env/bin/flake8

docker_up:
	docker compose up --build -d function

docker_down:
	docker compose down --remove-orphans

.PHONY: docker_event
docker_event: docker_restart
	curl --request POST \
		--url http://localhost:9000/2015-03-31/functions/function/invocations \
		--header 'Content-Type: application/json' \
		--data @tests/sample_event.json

.PHONY: docker_restart
docker_restart:
	# Code changes are synced via volume mount, but the container needs to be restarted to pick up changes.
	# If you need to change env vars, do `make docker_down` then `make docker_up` before `make docker_event`.
	docker compose restart function
	# Giving the container sufficient time to restart. Adjust this delay if `make docker_event` fails.
	sleep 0.5  # sleep value is in seconds

docker_test:
	docker compose up \
		--exit-code-from lint-and-test \
		--abort-on-container-exit \
		--build lint-and-test
