diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml index 815d462..4f5156b 100644 --- a/.github/workflows/on_push.yml +++ b/.github/workflows/on_push.yml @@ -12,9 +12,27 @@ jobs: steps: # need checkout before using docker-compose-action - uses: actions/checkout@v3 - - uses: adambirds/docker-compose-action@v1.3.0 + - uses: isbang/compose-action@v1.5.1 with: compose-file: "docker-compose.yml" down-flags: "--volumes --remove-orphans --rmi local" - test-container: "blood-info" - test-command: "$(wget -q -O- --no-check-certificate https://localhost:8443/station | jq '. | length') -gt 0" + services: | + db + blood-info + scraper + + - name: Run Tests + shell: bash + run: sleep 10 && docker-compose run --rm test + + - uses: isbang/compose-action@v1.5.1 + with: + compose-file: "docker-compose.yml" + down-flags: "--volumes --remove-orphans --rmi local" + services: | + test + + - name: Stop + if: always() + shell: bash + run: docker-compose down diff --git a/docker-compose.yml b/docker-compose.yml index 8b0d90a..9b03039 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,3 +38,8 @@ services: environment: - SCRAPER_INTERVAL=300 + test: + build: + context: . + dockerfile: test/integration/Dockerfile.test + diff --git a/test/integration/test.sh b/test/integration/test.sh new file mode 100755 index 0000000..7730554 --- /dev/null +++ b/test/integration/test.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# Define variables +total_duration=30 # Total duration in seconds +interval=5 # Interval in seconds +end_time=$(($(date +%s) + total_duration)) + +# Run the test in a loop +while [ $(date +%s) -lt $end_time ]; do + result=$(wget -q -O- --no-check-certificate https://blood-info:8443/stations | jq '. | length') + if [ -n "$result" ] && [ "$result" -ne 0 ]; then + echo "Test passed: There are $result stations reported." + exit 0 + fi + + sleep $interval # Wait for the specified interval before the next test +done + +echo "Test failed: Result is empty or zero." +exit 1 # Test failed