.PHONY: pip_dev lint test_unit test up down execute-existing execute-new

pip_dev: requirements.txt requirements-test.txt
	python -m venv env
	env/bin/pip install --upgrade pip
	env/bin/pip install -r requirements.txt
	env/bin/pip install -r requirements-test.txt

lint: pip_dev tests/
	env/bin/flake8 src/ tests/

test_unit: pip_dev
	Environment=test env/bin/python -m pytest \
		--cov src tests/unit/ \
		--cov-report xml \
		--junitxml=pyunit.xml

test:  ## Lint and test
	docker compose up --build lint-and-test

up:  ## Start container
	docker compose up --build -d function

down: ## Shutdown docker
	docker compose down

execute-existing: ## Execute function with existing correlation id
	curl --request POST \
	  --url http://localhost:9000/2015-03-31/functions/function/invocations \
	  --header 'Content-Type: application/json' \
	  --data @tests/sample_event.json

execute-new: ## Execute function with new correlation id
	@curl --request POST \
	  --url http://localhost:9000/2015-03-31/functions/function/invocations \
	  --header 'Content-Type: application/json' \
	  --data "$$(env/bin/python tests/generate_event.py)"
