@@ -5,6 +5,14 @@ set -euo pipefail
55# Generic test runner script
66# Usage: run-test.sh <test-type>
77# Where test-type is one of: unit, integration, contract, schema, acceptance
8+ #
9+ # Behaviour varies by environment (ENV variable, loaded from .env):
10+ # ENV=local → runs pytest directly against the local Lambda/RIE
11+ # ENV=remote → passes --env=remote, --api-name, --proxy-name, and
12+ # --apigee-access-token to pytest so the pytest-nhsd-apim
13+ # plugin can authenticate with the APIM proxy.
14+ #
15+ # Unit tests always run in local mode regardless of ENV.
816
917if [[ $# -ne 1 ]]; then
1018 echo " Usage: $0 <test-type>"
@@ -16,16 +24,16 @@ TEST_TYPE="$1"
1624
1725# Validate test type early
1826if [[ ! " $TEST_TYPE " =~ ^(unit| integration| contract| schema| acceptance)$ ]]; then
19- echo " Error: Unknown test type '$TEST_TYPE '" >&2
20- echo " Valid types are: unit, integration, contract, schema, acceptance" >&2
27+ echo " Error: Unknown test type '$TEST_TYPE '"
28+ echo " Valid types are: unit, integration, contract, schema, acceptance"
2129 exit 1
2230fi
2331
2432cd " $( git rev-parse --show-toplevel) "
2533
2634# Determine test path based on test type
2735if [[ " $TEST_TYPE " = " unit" ]]; then
28- TEST_PATH=" src"
36+ TEST_PATH=" test_*.py src/ "
2937else
3038 TEST_PATH=" tests/${TEST_TYPE} /"
3139fi
@@ -35,27 +43,32 @@ mkdir -p test-artefacts
3543
3644echo " Running ${TEST_TYPE} tests..."
3745
46+ # Set coverage path based on test type
3847if [[ " $TEST_TYPE " = " unit" ]]; then
3948 COV_PATH=" ."
49+ else
50+ COV_PATH=" src/gateway_api"
51+ fi
4052
41- poetry run pytest ${TEST_PATH} -v \
42- --cov=${COV_PATH} \
53+ if [[ " $ENV " = " remote" ]] && [[ " $TEST_TYPE " != " unit" ]]; then
54+ # Note: TEST_PATH is intentionally unquoted to allow glob expansion for unit tests
55+ poetry run pytest ${TEST_PATH} --env=" remote" -v \
56+ --api-name=" ${PROXYGEN_API_NAME} " --proxy-name=" ${PROXYGEN_API_NAME} --internal-dev--${PROXYGEN_API_NAME} -pr-${PR_NUMBER} " \
57+ --apigee-access-token=" ${APIGEE_ACCESS_TOKEN} " \
58+ --cov=" ${COV_PATH} " \
4359 --cov-report=html:test-artefacts/coverage-html \
4460 --cov-report=term \
4561 --junit-xml=" test-artefacts/${TEST_TYPE} -tests.xml" \
4662 --html=" test-artefacts/${TEST_TYPE} -tests.html" --self-contained-html
4763else
48- COV_PATH=" src/gateway_api"
49- TEST_ENV=" ${ENV:- local} "
50-
5164 poetry run pytest ${TEST_PATH} -v \
52- --env=" ${TEST_ENV} " \
53- --cov=${COV_PATH} \
65+ --cov=" ${COV_PATH} " \
5466 --cov-report=html:test-artefacts/coverage-html \
5567 --cov-report=term \
5668 --junit-xml=" test-artefacts/${TEST_TYPE} -tests.xml" \
5769 --html=" test-artefacts/${TEST_TYPE} -tests.html" --self-contained-html
5870fi
5971
72+
6073# Save coverage data file for merging
6174mv .coverage " test-artefacts/coverage.${TEST_TYPE} "
0 commit comments