Skip to content

Commit 2f6a4ed

Browse files
test-suite
1 parent bc8f9f4 commit 2f6a4ed

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

scripts/tests/run-test.sh

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

917
if [[ $# -ne 1 ]]; then
1018
echo "Usage: $0 <test-type>"
@@ -16,16 +24,16 @@ TEST_TYPE="$1"
1624

1725
# Validate test type early
1826
if [[ ! "$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
2230
fi
2331

2432
cd "$(git rev-parse --show-toplevel)"
2533

2634
# Determine test path based on test type
2735
if [[ "$TEST_TYPE" = "unit" ]]; then
28-
TEST_PATH="src"
36+
TEST_PATH="test_*.py src/"
2937
else
3038
TEST_PATH="tests/${TEST_TYPE}/"
3139
fi
@@ -35,27 +43,32 @@ mkdir -p test-artefacts
3543

3644
echo "Running ${TEST_TYPE} tests..."
3745

46+
# Set coverage path based on test type
3847
if [[ "$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
4763
else
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
5870
fi
5971

72+
6073
# Save coverage data file for merging
6174
mv .coverage "test-artefacts/coverage.${TEST_TYPE}"

scripts/tests/test.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ env-remote:
133133
cp -f .env.remote .env
134134
@echo "Activated remote environment: .env.remote -> .env (ENV=remote)"
135135

136-
# Run tests against local lambda
136+
# Run tests against local
137137
test-local: env-local
138138
@set -a && source .env && set +a && \
139139
$(MAKE) test
140140

141-
# Run tests against remote lambda, exporting APIGEE_ACCESS_TOKEN only
141+
# Run tests against remote, exporting APIGEE_ACCESS_TOKEN only
142142
test-remote: env-remote
143143
@echo "Obtaining APIGEE access token..."
144144
@set -a && source .env && set +a && \

0 commit comments

Comments
 (0)