Skip to content

Commit d769083

Browse files
[CDAPI-100]: Remote APIM testing completed in preview env
1 parent 84ef272 commit d769083

File tree

3 files changed

+126
-168
lines changed

3 files changed

+126
-168
lines changed

.github/workflows/preview-env.yaml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ env:
2323
PROXYGEN_KEY_ID: ${{ vars.PREVIEW_ENV_PROXYGEN_KEY_ID }}
2424
PROXYGEN_CLIENT_ID: ${{ vars.PREVIEW_ENV_PROXYGEN_CLIENT_ID }}
2525
PROXYGEN_API_NAME: ${{ vars.PROXYGEN_API_NAME }}
26+
BASE_URL: "https://internal-dev.api.service.nhs.uk/pathology-laboratory-reporting-pr-32"
27+
ENV: "remote"
28+
PR_NUMBER: ${{ github.event.pull_request.number }}
2629

2730
jobs:
2831
pr-preview:
@@ -236,6 +239,127 @@ jobs:
236239
proxygen-client-id: ${{ env.PROXYGEN_CLIENT_ID }}
237240
proxygen-api-name: ${{ env.PROXYGEN_API_NAME }}
238241

242+
- name: Retrieve Apigee Token
243+
id: apigee-token
244+
shell: bash
245+
run: |
246+
set -euo pipefail
247+
248+
APIGEE_TOKEN="$(proxygen pytest-nhsd-apim get-token | jq -r '.pytest_nhsd_apim_token' 2>/dev/null)"
249+
if [ -z "$APIGEE_TOKEN" ] || [ "$APIGEE_TOKEN" = "null" ]; then
250+
echo "::error::Failed to retrieve Apigee token"
251+
exit 1
252+
fi
253+
254+
echo "::add-mask::$APIGEE_TOKEN"
255+
echo "mask-test: $APIGEE_TOKEN"
256+
printf 'apigee-access-token=%s\n' "$APIGEE_TOKEN" >> "$GITHUB_OUTPUT"
257+
echo "Token retrieved successfully (length: ${#APIGEE_TOKEN})"
258+
259+
- name: "Create coverage artefact name"
260+
id: create-name
261+
uses: ./.github/actions/create-artefact-name
262+
with:
263+
prefix: coverage
264+
265+
- name: "Run contract tests"
266+
run: make test-contract
267+
- name: "Upload contract test results"
268+
if: always()
269+
uses: actions/upload-artifact@v6
270+
with:
271+
name: contract-test-results
272+
path: pathology-api/test-artefacts/
273+
retention-days: 30
274+
- name: "Publish contract test results to summary"
275+
if: always()
276+
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
277+
with:
278+
paths: pathology-api/test-artefacts/contract-tests.xml
279+
280+
- name: "Run schema validation tests"
281+
run: make test-schema
282+
- name: "Upload schema test results"
283+
if: always()
284+
uses: actions/upload-artifact@v6
285+
with:
286+
name: schema-test-results
287+
path: pathology-api/test-artefacts/
288+
retention-days: 30
289+
- name: "Publish schema test results to summary"
290+
if: always()
291+
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
292+
with:
293+
paths: pathology-api/test-artefacts/schema-tests.xml
294+
295+
- name: "Run integration test"
296+
run: make test-integration
297+
- name: "Upload integration test results"
298+
if: always()
299+
uses: actions/upload-artifact@v6
300+
with:
301+
name: integration-test-results
302+
path: pathology-api/test-artefacts/
303+
retention-days: 30
304+
- name: "Publish integration test results to summary"
305+
if: always()
306+
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
307+
with:
308+
paths: pathology-api/test-artefacts/integration-tests.xml
309+
310+
- name: "Run acceptance test"
311+
run: make test-acceptance
312+
- name: "Upload acceptance test results"
313+
if: always()
314+
uses: actions/upload-artifact@v6
315+
with:
316+
name: acceptance-test-results
317+
path: pathology-api/test-artefacts/
318+
retention-days: 30
319+
- name: "Publish acceptance test results to summary"
320+
if: always()
321+
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
322+
with:
323+
paths: pathology-api/test-artefacts/acceptance-tests.xml
324+
325+
- name: "Download all test coverage artefacts"
326+
uses: actions/download-artifact@v7
327+
with:
328+
path: pathology-api/test-artefacts/
329+
merge-multiple: false
330+
- name: "Merge coverage data"
331+
run: make test-coverage
332+
- name: "Rename coverage XML with unique name"
333+
run: |
334+
cd pathology-api/test-artefacts
335+
mv coverage-merged.xml ${{ needs.create-coverage-name.outputs.coverage-name }}.xml
336+
- name: "Upload combined coverage report"
337+
if: always()
338+
uses: actions/upload-artifact@v6
339+
with:
340+
name: ${{ needs.create-coverage-name.outputs.coverage-name }}
341+
path: pathology-api/test-artefacts
342+
retention-days: 30
343+
344+
- name: "Checkout code"
345+
uses: actions/checkout@v6
346+
with:
347+
fetch-depth: 0 # Full history is needed for better analysis
348+
- name: "Download merged coverage report"
349+
uses: actions/download-artifact@v7
350+
with:
351+
name: ${{ needs.create-coverage-name.outputs.coverage-name }}
352+
path: coverage-reports/
353+
- name: "SonarCloud Scan"
354+
uses: SonarSource/sonarqube-scan-action@v7
355+
env:
356+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
357+
with:
358+
args: >
359+
-Dsonar.organization=${{ vars.SONAR_ORGANISATION_KEY }}
360+
-Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }}
361+
-Dsonar.python.coverage.reportPaths=coverage-reports/${{ needs.create-coverage-name.outputs.coverage-name }}.xml
362+
239363
- name: Comment function name on PR
240364
if: github.event_name == 'pull_request' && github.event.action != 'closed'
241365
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
Lines changed: 1 addition & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
name: "Test stage"
22

3-
permissions:
4-
id-token: write
5-
contents: read
6-
73
env:
8-
BASE_URL: "https://internal-dev.api.service.nhs.uk/pathology-laboratory-reporting-pr-32"
4+
BASE_URL: "http://localhost:5002"
95
HOST: "localhost"
10-
ENV: "remote"
11-
PR_NUMBER: "32"
12-
AWS_REGION: eu-west-2
13-
PROXYGEN_KEY_ID: ${{ vars.PREVIEW_ENV_PROXYGEN_KEY_ID }}
14-
PROXYGEN_CLIENT_ID: ${{ vars.PREVIEW_ENV_PROXYGEN_CLIENT_ID }}
15-
PROXYGEN_API_NAME: ${{ vars.PROXYGEN_API_NAME }}
166

177
on:
188
workflow_call:
@@ -37,97 +27,13 @@ jobs:
3727
with:
3828
prefix: coverage
3929

40-
generate-apigee-token:
41-
name: "Generate Apigee token"
42-
runs-on: ubuntu-latest
43-
outputs:
44-
secret-name: ${{ steps.store-token.outputs.secret-name }}
45-
steps:
46-
- name: "Checkout code"
47-
uses: actions/checkout@v6
48-
49-
- name: "Set up Python"
50-
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
51-
with:
52-
python-version: ${{ inputs.python_version }}
53-
54-
- name: Select AWS role inputs
55-
id: role-select
56-
env:
57-
DEPENDABOT_AWS_ROLE_ARN: ${{ secrets.DEPENDABOT_AWS_ROLE_ARN }}
58-
DEPENDABOT_LAMBDA_ROLE_ARN: ${{ secrets.DEPENDABOT_LAMBDA_ROLE_ARN }}
59-
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
60-
LAMBDA_ROLE_ARN: ${{ secrets.LAMBDA_ROLE_ARN }}
61-
run: |
62-
if [ "${{ github.actor }}" = "dependabot[bot]" ]; then
63-
echo "aws_role=$DEPENDABOT_AWS_ROLE_ARN" >> "$GITHUB_OUTPUT"
64-
echo "lambda_role=$DEPENDABOT_LAMBDA_ROLE_ARN" >> "$GITHUB_OUTPUT"
65-
else
66-
echo "aws_role=$AWS_ROLE_ARN" >> "$GITHUB_OUTPUT"
67-
echo "lambda_role=$LAMBDA_ROLE_ARN" >> "$GITHUB_OUTPUT"
68-
fi
69-
70-
- name: Configure AWS credentials (OIDC)
71-
uses: aws-actions/configure-aws-credentials@a7a2c1125c67f40a1e95768f4e4a7d8f019f87af
72-
with:
73-
role-to-assume: ${{ steps.role-select.outputs.aws_role }}
74-
aws-region: ${{ env.AWS_REGION }}
75-
76-
- name: Get proxygen machine user details
77-
id: proxygen-machine-user
78-
uses: aws-actions/aws-secretsmanager-get-secrets@a9a7eb4e2f2871d30dc5b892576fde60a2ecc802
79-
with:
80-
secret-ids: /cds/pathology/dev/proxygen/proxygen-key-secret
81-
name-transformation: lowercase
82-
83-
- name: Generate Apigee token
84-
id: generate-token
85-
uses: ./.github/actions/proxy/generate-apigee-token
86-
with:
87-
proxygen-key-secret: ${{ env._cds_pathology_dev_proxygen_proxygen_key_secret }}
88-
proxygen-key-id: ${{ env.PROXYGEN_KEY_ID }}
89-
proxygen-client-id: ${{ env.PROXYGEN_CLIENT_ID }}
90-
proxygen-api-name: ${{ env.PROXYGEN_API_NAME }}
91-
92-
- name: Store token in AWS Secrets Manager
93-
id: store-token
94-
shell: bash
95-
env:
96-
TOKEN: ${{ steps.generate-token.outputs.apigee-access-token }}
97-
run: |
98-
if [ -z "$TOKEN" ]; then
99-
echo "::error::Token is empty"
100-
exit 1
101-
fi
102-
SECRET_NAME="apigee-token-${{ github.run_id }}-${{ github.run_attempt }}"
103-
aws secretsmanager create-secret \
104-
--name "$SECRET_NAME" \
105-
--description "Temporary Apigee token for workflow run ${{ github.run_id }}" \
106-
--secret-string "$TOKEN" \
107-
--region ${{ env.AWS_REGION }}
108-
echo "secret-name=$SECRET_NAME" >> $GITHUB_OUTPUT
109-
echo "Token stored securely in AWS Secrets Manager: $SECRET_NAME"
110-
11130
test-unit:
11231
name: "Unit tests"
11332
runs-on: ubuntu-latest
11433
timeout-minutes: 5
115-
needs: [generate-apigee-token]
116-
env:
117-
ENV: "local"
11834
steps:
11935
- name: "Checkout code"
12036
uses: actions/checkout@v6
121-
- name: Retrieve Apigee token
122-
id: get-token
123-
uses: ./.github/actions/retrieve-apigee-token
124-
with:
125-
secret-name: ${{ needs.generate-apigee-token.outputs.secret-name }}
126-
aws-role-arn: ${{ secrets.AWS_ROLE_ARN }}
127-
aws-region: ${{ env.AWS_REGION }}
128-
- name: Set token environment variable
129-
shell: bash
130-
run: echo "APIGEE_ACCESS_TOKEN=${{ steps.get-token.outputs.apigee-access-token }}" >> $GITHUB_ENV
13137
- name: "Setup Python project"
13238
uses: ./.github/actions/setup-python-project
13339
with:
@@ -151,20 +57,9 @@ jobs:
15157
name: "Contract tests"
15258
runs-on: ubuntu-latest
15359
timeout-minutes: 5
154-
needs: [generate-apigee-token]
15560
steps:
15661
- name: "Checkout code"
15762
uses: actions/checkout@v6
158-
- name: Retrieve Apigee token
159-
id: get-token
160-
uses: ./.github/actions/retrieve-apigee-token
161-
with:
162-
secret-name: ${{ needs.generate-apigee-token.outputs.secret-name }}
163-
aws-role-arn: ${{ secrets.AWS_ROLE_ARN }}
164-
aws-region: ${{ env.AWS_REGION }}
165-
- name: Set token environment variable
166-
shell: bash
167-
run: echo "APIGEE_ACCESS_TOKEN=${{ steps.get-token.outputs.apigee-access-token }}" >> $GITHUB_ENV
16863
- name: "Setup Python project"
16964
uses: ./.github/actions/setup-python-project
17065
with:
@@ -192,20 +87,9 @@ jobs:
19287
name: "Schema validation tests"
19388
runs-on: ubuntu-latest
19489
timeout-minutes: 5
195-
needs: [generate-apigee-token]
19690
steps:
19791
- name: "Checkout code"
19892
uses: actions/checkout@v6
199-
- name: Retrieve Apigee token
200-
id: get-token
201-
uses: ./.github/actions/retrieve-apigee-token
202-
with:
203-
secret-name: ${{ needs.generate-apigee-token.outputs.secret-name }}
204-
aws-role-arn: ${{ secrets.AWS_ROLE_ARN }}
205-
aws-region: ${{ env.AWS_REGION }}
206-
- name: Set token environment variable
207-
shell: bash
208-
run: echo "APIGEE_ACCESS_TOKEN=${{ steps.get-token.outputs.apigee-access-token }}" >> $GITHUB_ENV
20993
- name: "Setup Python project"
21094
uses: ./.github/actions/setup-python-project
21195
with:
@@ -233,20 +117,9 @@ jobs:
233117
name: "Integration tests"
234118
runs-on: ubuntu-latest
235119
timeout-minutes: 10
236-
needs: [generate-apigee-token]
237120
steps:
238121
- name: "Checkout code"
239122
uses: actions/checkout@v6
240-
- name: Retrieve Apigee token
241-
id: get-token
242-
uses: ./.github/actions/retrieve-apigee-token
243-
with:
244-
secret-name: ${{ needs.generate-apigee-token.outputs.secret-name }}
245-
aws-role-arn: ${{ secrets.AWS_ROLE_ARN }}
246-
aws-region: ${{ env.AWS_REGION }}
247-
- name: Set token environment variable
248-
shell: bash
249-
run: echo "APIGEE_ACCESS_TOKEN=${{ steps.get-token.outputs.apigee-access-token }}" >> $GITHUB_ENV
250123
- name: "Setup Python project"
251124
uses: ./.github/actions/setup-python-project
252125
with:
@@ -256,7 +129,6 @@ jobs:
256129
with:
257130
python-version: ${{ inputs.python_version }}
258131
- name: "Run integration test"
259-
shell: bash
260132
run: make test-integration
261133
- name: "Upload integration test results"
262134
if: always()
@@ -275,20 +147,9 @@ jobs:
275147
name: "Acceptance tests"
276148
runs-on: ubuntu-latest
277149
timeout-minutes: 10
278-
needs: [generate-apigee-token]
279150
steps:
280151
- name: "Checkout code"
281152
uses: actions/checkout@v6
282-
- name: Retrieve Apigee token
283-
id: get-token
284-
uses: ./.github/actions/retrieve-apigee-token
285-
with:
286-
secret-name: ${{ needs.generate-apigee-token.outputs.secret-name }}
287-
aws-role-arn: ${{ secrets.AWS_ROLE_ARN }}
288-
aws-region: ${{ env.AWS_REGION }}
289-
- name: Set token environment variable
290-
shell: bash
291-
run: echo "APIGEE_ACCESS_TOKEN=${{ steps.get-token.outputs.apigee-access-token }}" >> $GITHUB_ENV
292153
- name: "Setup Python project"
293154
uses: ./.github/actions/setup-python-project
294155
with:
@@ -369,30 +230,3 @@ jobs:
369230
-Dsonar.organization=${{ vars.SONAR_ORGANISATION_KEY }}
370231
-Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }}
371232
-Dsonar.python.coverage.reportPaths=coverage-reports/${{ needs.create-coverage-name.outputs.coverage-name }}.xml
372-
373-
cleanup-apigee-token:
374-
name: "Cleanup Apigee token"
375-
runs-on: ubuntu-latest
376-
needs: [generate-apigee-token, test-unit, test-contract, test-schema, test-integration, test-acceptance]
377-
if: always()
378-
timeout-minutes: 2
379-
steps:
380-
- name: Configure AWS credentials
381-
uses: aws-actions/configure-aws-credentials@a7a2c1125c67f40a1e95768f4e4a7d8f019f87af
382-
with:
383-
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
384-
aws-region: ${{ env.AWS_REGION }}
385-
386-
- name: Delete secret from AWS Secrets Manager
387-
shell: bash
388-
run: |
389-
SECRET_NAME="${{ needs.generate-apigee-token.outputs.secret-name }}"
390-
if [ -n "$SECRET_NAME" ]; then
391-
aws secretsmanager delete-secret \
392-
--secret-id "$SECRET_NAME" \
393-
--force-delete-without-recovery \
394-
--region ${{ env.AWS_REGION }} || true
395-
echo "Secret $SECRET_NAME deleted from Secrets Manager"
396-
else
397-
echo "No secret name provided, skipping cleanup"
398-
fi

pathology-api/tests/integration/test_endpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_bundle_returns_200(self, client: Client) -> None:
1717
type="document",
1818
entry=[
1919
Bundle.Entry(
20-
fullUrl="patient",
20+
fullUrl="composition",
2121
resource=Composition.create(
2222
subject=LogicalReference(
2323
PatientIdentifier.from_nhs_number("nhs_number")

0 commit comments

Comments
 (0)