diff --git a/.forgejo/workflows/integration-test.yaml b/.forgejo/workflows/integration-test.yaml index 2faf7d5..27e58b2 100644 --- a/.forgejo/workflows/integration-test.yaml +++ b/.forgejo/workflows/integration-test.yaml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: environment: - description: "Environment to deploy to" + description: "Target environment" required: true default: "testing" type: choice @@ -14,13 +14,13 @@ on: - production jobs: - testing: - if: github.event.inputs.environment == 'testing' + # YAML anchor for common job configuration + .integration-test: &integration-test runs-on: general container: image: "ghcr.io/catthehacker/ubuntu:js-24.04" - environment: testing - + env: + TARGET_ENVIRONMENT: ${{ github.event.inputs.environment }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -30,49 +30,22 @@ jobs: apt-get update apt-get install -y python3-pytest python3-requests - - name: Run test (Testing) + - name: Run integration tests run: | - echo "Running integration tests for TESTING environment" + echo "Running integration tests for ${TARGET_ENVIRONMENT^^} environment" pytest run_test.py + testing: + if: github.event.inputs.environment == 'testing' + environment: testing + <<: *integration-test + staging: if: github.event.inputs.environment == 'staging' - runs-on: general - container: - image: "ghcr.io/catthehacker/ubuntu:js-24.04" environment: staging - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - apt-get update - apt-get install -y python3-pytest python3-requests - - - name: Run test (Staging) - run: | - echo "Running integration tests for STAGING environment" - pytest run_test.py + <<: *integration-test production: if: github.event.inputs.environment == 'production' - runs-on: general - container: - image: "ghcr.io/catthehacker/ubuntu:js-24.04" environment: production - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - apt-get update - apt-get install -y python3-pytest python3-requests - - - name: Run test (Production) - run: | - echo "Running integration tests for PRODUCTION environment" - pytest run_test.py + <<: *integration-test diff --git a/run_test.py b/run_test.py index 42bd437..704d3e1 100644 --- a/run_test.py +++ b/run_test.py @@ -1,3 +1,4 @@ +import os import pytest import requests @@ -11,7 +12,13 @@ def test_health_endpoint(): - The response is valid JSON - The response contains results.message == "ok" """ - url = "https://api.cleverbrag.epsilon.cleverthis.com/v3/health" + urls = { + "testing": "https://api.cleverbrag.epsilon.cleverthis.com", + "staging": "https://api.cleverbrag.delta.cleverthis.com", + "production": "https://api.cleverbrag.cleverthis.com", + } + + url = urls[os.getenv("TARGET_ENVIRONMENT")] # Make the HTTP request response = requests.get(url) @@ -35,6 +42,7 @@ def test_health_endpoint(): if __name__ == "__main__": + print(f"Running pytest in {TARGET_ENVIRONMENT}") # Allow running the test directly with python run_test.py test_health_endpoint() print("Health endpoint test passed!")