diff --git a/.github/actions/pytest-with-rerun/action.yml b/.github/actions/pytest-with-rerun/action.yml index e2b196cdf..6dbcac6aa 100644 --- a/.github/actions/pytest-with-rerun/action.yml +++ b/.github/actions/pytest-with-rerun/action.yml @@ -8,12 +8,16 @@ inputs: description: "[Optional] Assume the CI AWS Role during this operation?" required: false default: "" + workspace: + description: "[Optional] Workspace to derive secret from" + required: false + default: "" runs: using: "composite" steps: - uses: ./.github/actions/make/ with: - command: test--${{ inputs.test-type }} + command: test--${{ inputs.test-type }} WORKSPACE="${{ inputs.workspace }}" requires-aws: ${{ inputs.requires-aws }} - uses: ./.github/actions/make/ diff --git a/.github/workflows/_deploy.yml b/.github/workflows/_deploy.yml index 53c102072..11e25cc57 100644 --- a/.github/workflows/_deploy.yml +++ b/.github/workflows/_deploy.yml @@ -155,12 +155,11 @@ jobs: - uses: actions/checkout@v4 with: ref: ${{ needs.get-branch-from-workflow-file.outputs.branch_name }} - - uses: ./.github/actions/make/ + - uses: ./.github/actions/pytest-with-rerun/ with: - command: test--smoke + test-type: smoke workspace: ${{ env.WORKSPACE }} requires-aws: true - cache-suffix: ${{ env.CACHE_NAME }} set-success: name: Set Success diff --git a/src/conftest.py b/conftest.py similarity index 93% rename from src/conftest.py rename to conftest.py index fc5664fba..286b3e4c7 100644 --- a/src/conftest.py +++ b/conftest.py @@ -2,6 +2,7 @@ from pathlib import Path import boto3 +import pytest from event.aws.client import dynamodb_client from event.logging.logger import setup_logger from nhs_context_logging.fixtures import ( # noqa: F401 @@ -118,3 +119,17 @@ def test_data_paths(request: FixtureRequest): yield paths else: yield + + +def pytest_addoption(parser): + parser.addoption( + "--workspace", + action="store", + default="per_workspace", + help="workspace", + ) + + +@pytest.fixture +def workspace(request): + return request.config.getoption("--workspace") diff --git a/scripts/test/test.mk b/scripts/test/test.mk index 62f41b5e1..74453f060 100644 --- a/scripts/test/test.mk +++ b/scripts/test/test.mk @@ -20,7 +20,7 @@ test--s3: aws--login ## Run (pytest) tests that require s3 downloads $(MAKE) _pytest _INTERNAL_FLAGS="-m 's3'" _CACHE_CLEAR=$(_CACHE_CLEAR) AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) AWS_SESSION_TOKEN=$(AWS_SESSION_TOKEN) test--smoke: aws--login ## Run end-to-end smoke tests (pytest) - $(MAKE) _pytest _INTERNAL_FLAGS="-m 'smoke'" _CACHE_CLEAR=$(_CACHE_CLEAR) AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) AWS_SESSION_TOKEN=$(AWS_SESSION_TOKEN) + $(MAKE) _pytest _INTERNAL_FLAGS="-m 'smoke' --workspace=$(WORKSPACE)" _CACHE_CLEAR=$(_CACHE_CLEAR) AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) AWS_SESSION_TOKEN=$(AWS_SESSION_TOKEN) test--%--rerun: ## Rerun failed integration or unit (pytest) tests $(MAKE) test--$* _INTERNAL_FLAGS="--last-failed --last-failed-no-failures none" _CACHE_CLEAR= diff --git a/src/smoke_tests/test_smoke.py b/src/smoke_tests/test_smoke.py index 14bf0c840..667975f2d 100644 --- a/src/smoke_tests/test_smoke.py +++ b/src/smoke_tests/test_smoke.py @@ -7,7 +7,6 @@ from event.json import json_loads from test_helpers.sample_data import ORGANISATION -from test_helpers.terraform import read_terraform_output class SmokeTestError(Exception): @@ -83,9 +82,7 @@ def create_apigee_url(apigee_env: str, workspace: str): def _prepare_base_request(workspace: str) -> tuple[str, dict]: client = boto3.client("secretsmanager") workspace = "dev" if workspace not in PERSISTENT_ENVS else workspace - secret_name = f"{workspace}-apigee-app-key" - secret = client.get_secret_value(SecretId=secret_name) appkey = secret["SecretString"] @@ -105,9 +102,8 @@ def _prepare_base_request(workspace: str) -> tuple[str, dict]: @pytest.mark.smoke -def test_smoke_tests(): +def test_smoke_tests(workspace): print("🏃 Running 🏃 smoke test - 🤔") # noqa: T201 - workspace = read_terraform_output("workspace.value") base_url, headers = _prepare_base_request(workspace=workspace) for request_method in REQUEST_METHODS: response = request_method(base_url=base_url, headers=headers)