From 0d519ec14f2c32014e0f76ad1fe55a54d8f5d690 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Sun, 25 May 2025 21:23:29 +0300 Subject: [PATCH] make cleanup happen even if workflow fails --- .gitea/workflows/test-backend.yaml | 9 ++++++++- backend/db/populate.sql | 7 +++++++ tests/backend.sh | 14 +++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 backend/db/populate.sql diff --git a/.gitea/workflows/test-backend.yaml b/.gitea/workflows/test-backend.yaml index 4d4c69d..a5a380f 100644 --- a/.gitea/workflows/test-backend.yaml +++ b/.gitea/workflows/test-backend.yaml @@ -17,11 +17,18 @@ jobs: - name: Deploy testing environment shell: sh run: docker-compose -f backend/docker-compose-x86_64.yaml up -d + - name: Add tables to DB + shell: sh + run: docker-compose -f backend/docker-compose-x86_64.yaml exec -T postgres psql -U postgres < backend/db/create.sql + - name: Populate DB + shell: sh + run: docker-compose -f backend/docker-compose-x86_64.yaml exec -T postgres psql -U postgres < backend/db/populate.sql - name: Run test requests shell: sh run: | chmod +x tests/backend.sh tests/backend.sh - name: Clean up testing environment + if: always() shell: sh - run: docker-compose -f backend/docker-compose-x86_64.yaml up -d + run: docker-compose -f backend/docker-compose-x86_64.yaml down diff --git a/backend/db/populate.sql b/backend/db/populate.sql new file mode 100644 index 0000000..15ae63a --- /dev/null +++ b/backend/db/populate.sql @@ -0,0 +1,7 @@ +INSERT INTO public.movie (uuid, name, scheduled_datetime, movie_details, image_url, max_passes) +VALUES ('742a2542-2b50-11f0-ae4c-f7bedd5fcc88', + 'Movie 1', + '1997-12-15 21:30:00', + 'This movie dives deep into many topics...', + 'https://cdn.cinema.com/img/movie1.webp', + 150); diff --git a/tests/backend.sh b/tests/backend.sh index 46757ff..752c6a7 100644 --- a/tests/backend.sh +++ b/tests/backend.sh @@ -13,17 +13,18 @@ assert_bad_status () { } HOST=127.0.0.1 +ARGS="--fail-with-body" -curl -f http://$HOST/movies +curl $ARGS http://$HOST/movies assert_good_status -curl -f http://$HOST/passes +curl $ARGS http://$HOST/passes assert_good_status -curl -X POST -f http://$HOST/apply_for_pass +curl -X POST $ARGS http://$HOST/apply_for_pass assert_bad_status -curl -X POST -f http://$HOST/apply_for_pass \ +curl -X POST $ARGS http://$HOST/apply_for_pass \ -H "Content-Type: application/json" \ --data '{"first": "Hannah", "last": "Dirt", @@ -33,5 +34,8 @@ curl -X POST -f http://$HOST/apply_for_pass \ "movie_uuid": "742a2542-2b50-11f0-ae4c-f7bedd5fcc88"}' assert_good_status -curl -f http://$HOST/passes | jq '.result.[0]' +sleep 10h + +curl $ARGS -s http://$HOST/passes +test [ $(curl $ARGS -s http://$HOST/passes | jq '.result.[0]') != "null" ] assert_good_status