From 7a3b13061497969453e9005636331ac11eb2c59e Mon Sep 17 00:00:00 2001 From: Tobias Waslowski Date: Tue, 9 Apr 2024 14:19:56 +0200 Subject: [PATCH] refactor test setup to use localstack in ci --- .github/workflows/build.yml | 4 +--- Makefile | 2 +- scripts/test.sh | 24 +++++++++--------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f8349c..2483c25 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,9 +53,7 @@ jobs: run: poetry install --no-interaction --no-root --with dev - name: Run tests - run: | - source .venv/bin/activate - export PYTHONPATH=./ && poetry run pytest test/ --ignore test/integration/manual/ --disable-warnings -s + run: bash -c scripts/test.sh create_infrastructure: needs: test diff --git a/Makefile b/Makefile index b644b18..1558548 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: test run fmt test: - @export PYTHONPATH=./ && poetry run pytest test/ --ignore test/integration/manual/ --disable-warnings -s + @bash -c 'scripts/test.sh' fmt: @bash -c 'pre-commit run -av' diff --git a/scripts/test.sh b/scripts/test.sh index b0d4f94..cfb9b8e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,21 +4,15 @@ docker run -d --rm --name localstack -p 4566:4566 -p 4571:4571 localstack/locals echo "waiting for localstack to be ready" sleep 3 -echo "creating user dynamodb table ..." -aws dynamodb create-table --table-name user \ - --attribute-definitions AttributeName=user_id,AttributeType=N \ - --key-schema AttributeName=user_id,KeyType=HASH \ - --billing-mode PAY_PER_REQUEST \ - --endpoint-url http://localhost:4566 > /dev/null +echo "running tests" +if [ -d .venv ]; then + echo "found existing virtual environment. activating ..." + source .venv/bin/activate +else + echo "no virtual environment found. assuming dependencies are available." +fi -echo "creating record dynamodb table ..." -aws dynamodb create-table --table-name record \ - --attribute-definitions AttributeName=timestamp,AttributeType=S \ - --attribute-definitions AttributeName=user_id,AttributeType=N \ - --key-schema AttributeName=timestamp,KeyType=RANGE \ - --key-schema AttributeName=user_id,KeyType=HASH \ - --billing-mode PAY_PER_REQUEST \ - --endpoint-url http://localhost:4566 > /dev/null +export PYTHONPATH=./ && poetry run pytest test/ --ignore test/integration/manual/ --disable-warnings -s echo "cleaning up" -# docker stop localstack +docker stop localstack