Skip to content

Commit ded557b

Browse files
CCM-17012: Enable e2e test on PR envs (#566)
* test pr proxy e2e tests * point to internal branch workflow * actually point to internal branch workflow for build proxies and run e2e on pr too * try to fix tests * Fix tests * Fix pact tests * create-letter-batch logs letterIds, e2e read and wait for queue * env template cleanup * env template cleanup 2 * smoking out failed tests * add markers * npm install * All tests run * ci(tests): pass targetAccountGroup through acceptance composite actions * infra: set shorter letter queue visibility timeout for dev group * component tests: centralize GET /letters retry handling and update specs * e2e: map account IDs by target group and block production test execution * update env template * env specific lambda runtime env vars * bump * revert lockfile * test with internal branch * remove internal ref * address copilot comments --------- Co-authored-by: Mark Slowey <113013138+masl2@users.noreply.github.com>
1 parent a276e1d commit ded557b

26 files changed

Lines changed: 450 additions & 146 deletions

File tree

.env.template

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
PR_NUMBER=prxx # remove if needs to run against main
2-
GITHUB_TOKEN= # Your github Personal Access Token (PAT)
1+
# Your github Personal Access Token (PAT)
2+
GITHUB_TOKEN=
33

4+
# Apigee proxy name to be used for test execution
5+
# nhs-notify-supplier--internal-dev--nhs-notify-supplier-PR-XX
6+
PROXY_NAME=
47

5-
# The variables below are used for End to End tests
6-
PROXY_NAME= # information about the proxy name can be found in the tests/e2e-tests/README.md
8+
# APIM env to run e2e tests against, other options are: ref, int, prod
9+
API_ENVIRONMENT=internal-dev
710

11+
# Used for component and e2e tests
12+
# Account group controls default account id mapping for tests.
13+
# If omitted, tests default to dev:
14+
# TARGET_ACCOUNT_GROUP=nhs-notify-supplier-api-dev
15+
# Mapping used by tests:
16+
# nhs-notify-supplier-api-dev -> 820178564574
17+
# nhs-notify-supplier-api-nonprod -> 885964308133
18+
# nhs-notify-supplier-api-prod -> blocked (tests are intentionally disabled for prod)
19+
TARGET_ACCOUNT_GROUP=nhs-notify-supplier-api-dev
820

9-
10-
# * nhs-notify-supplier--internal-dev--nhs-notify-supplier
11-
# * nhs-notify-supplier--internal-dev--nhs-notify-supplier-PR-XX
12-
# * nhs-notify-supplier--ref--nhs-notify-supplier -- ref env
21+
# Resource namespace used to resolve AWS resource names for tests (main, pr123)
22+
# remove if needs to run against main
23+
TARGET_ENVIRONMENT=prxx
1324

1425
# API Keys
1526
# ========
@@ -25,9 +36,9 @@ export STATUS_ENDPOINT_API_KEY=xxx
2536

2637
# Private Keys
2738
# ============
28-
# private key used to generate authentication for tests ran against the internal-dev and internal-qa
29-
export NON_PROD_PRIVATE_KEY=xxx # path to the private key file
30-
# private key used to generate authentication for tests ran against the int environment
39+
# private key path used to generate authentication for tests ran against the internal-dev and internal-qa
40+
export NON_PROD_PRIVATE_KEY=xxx
41+
# private key path used to generate authentication for tests ran against the int environment
3142
export INTEGRATION_PRIVATE_KEY=xxx
32-
# private key used to generate authentication for tests ran against the prod environment
43+
# private key path used to generate authentication for tests ran against the prod environment
3344
export PRODUCTION_PRIVATE_KEY=xxx

.github/actions/acceptance-tests-component/action.yml renamed to .github/actions/acceptance-tests-components/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ inputs:
1414
description: Name of the component under test
1515
required: true
1616

17+
targetAccountGroup:
18+
description: Name of the account group under test (e.g. nhs-notify-supplier-api-dev)
19+
required: true
20+
1721
runs:
1822
using: "composite"
1923

@@ -39,5 +43,6 @@ runs:
3943
shell: bash
4044
env:
4145
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
46+
TARGET_ACCOUNT_GROUP: ${{ inputs.targetAccountGroup }}
4247
run: |
4348
make test-${{ inputs.testType }}

.github/actions/acceptance-tests-e2e/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ inputs:
55
targetEnvironment:
66
description: Name of the environment under test
77
required: true
8+
targetAccountGroup:
9+
description: Name of the account group under test
10+
required: true
811

912
runs:
1013
using: "composite"
@@ -65,6 +68,7 @@ runs:
6568
env:
6669
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
6770
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
71+
TARGET_ACCOUNT_GROUP: ${{ inputs.targetAccountGroup }}
6872
run: |
6973
echo "$DEV_E2E_KEYS_PRIVATE" > "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
7074
chmod 600 "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"

.github/actions/acceptance-tests/action.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ inputs:
1111
required: true
1212

1313
targetAccountGroup:
14-
description: Name of the account group under test
15-
default: nhs-notify-template-management-dev
14+
description: Name of the account group under test (e.g. nhs-notify-supplier-api-dev)
1615
required: true
1716

1817
targetComponent:
@@ -24,16 +23,18 @@ runs:
2423

2524
steps:
2625

27-
- name: Run component tests
26+
- name: Run components tests (sandbox and component tests)
2827
if: ${{ inputs.testType != 'e2e' }}
29-
uses: ./.github/actions/acceptance-tests-component
28+
uses: ./.github/actions/acceptance-tests-components
3029
with:
3130
testType: ${{ inputs.testType }}
3231
targetEnvironment: ${{ inputs.targetEnvironment }}
3332
targetComponent: ${{ inputs.targetComponent }}
33+
targetAccountGroup: ${{ inputs.targetAccountGroup }}
3434

3535
- name: Run e2e tests
36-
if: ${{ inputs.testType == 'e2e' && inputs.targetEnvironment == 'main' }}
36+
if: ${{ inputs.testType == 'e2e' }}
3737
uses: ./.github/actions/acceptance-tests-e2e
3838
with:
3939
targetEnvironment: ${{ inputs.targetEnvironment }}
40+
targetAccountGroup: ${{ inputs.targetAccountGroup }}

.github/workflows/deploy-dynamic-env-proxy.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ jobs:
2929

3030
- name: Resolve nodejs version
3131
id: toolversions
32-
run: echo "nodejs_version=$(grep '^nodejs\s' .tool-versions | cut -f2 -d' ')" >>
32+
run:
33+
echo "nodejs_version=$(grep '^nodejs\s' .tool-versions | cut -f2 -d' ')" >>
3334
"$GITHUB_OUTPUT"
3435

3536
- name: "Check if pull request exists for this branch and set

.github/workflows/stage-3-build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ jobs:
189189
--terraformAction "apply" \
190190
--overrideProjectName "nhs" \
191191
--overrideRoleName "nhs-main-acct-supplier-api-github-deploy"
192+
192193
populate-config:
193194
name: "Populate Supplier Config"
194195
runs-on: ubuntu-latest

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# the project as automated steps to be executed on locally and in the CD pipeline.
33

44
include scripts/init.mk
5+
-include .env # Load environment variables from .env file if it exists
56

67
# ==============================================================================
78

@@ -130,11 +131,14 @@ ${VERBOSE}.SILENT: \
130131
# E2E Test commands #
131132
#####################
132133

134+
# https://pytest-xdist.readthedocs.io/en/stable/known-limitations.html#output-stdout-and-stderr-from-workers means pytest won't print to stdout even with -s
135+
PYTEST_WORKERS := 4 # set to 0 to see stdout/stderr when debugging e2e tests
136+
133137
TEST_CMD := APIGEE_ACCESS_TOKEN="$(APIGEE_ACCESS_TOKEN)" \
134138
STATUS_ENDPOINT_API_KEY="$(STATUS_ENDPOINT_API_KEY)" \
135139
PYTHONPATH=. poetry run pytest --disable-warnings -vv \
136140
--color=yes \
137-
-n 4 \
141+
-n $(PYTEST_WORKERS) \
138142
--api-name=nhs-notify-supplier \
139143
--proxy-name="$(PROXY_NAME)" \
140144
-s \
@@ -145,7 +149,6 @@ TEST_CMD := APIGEE_ACCESS_TOKEN="$(APIGEE_ACCESS_TOKEN)" \
145149
--only-rerun 'AssertionError: Unexpected 502' \
146150
--junitxml=test-report.xml
147151

148-
149152
.internal-dev-test:
150153
@cd tests/e2e-tests && \
151154
$(TEST_CMD) \
@@ -161,7 +164,7 @@ TEST_CMD := APIGEE_ACCESS_TOKEN="$(APIGEE_ACCESS_TOKEN)" \
161164
PROD_CMD := APIGEE_ACCESS_TOKEN="$(APIGEE_ACCESS_TOKEN)" \
162165
PYTHONPATH=. poetry run pytest --disable-warnings -vv \
163166
--color=yes \
164-
-n 4 \
167+
-n $(PYTEST_WORKERS) \
165168
--api-name=nhs-notify-supplier \
166169
--proxy-name="$(PROXY_NAME)" \
167170
-s \

infrastructure/terraform/components/api/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ No requirements.
1919
| <a name="input_csoc_log_forwarding"></a> [csoc\_log\_forwarding](#input\_csoc\_log\_forwarding) | Enable forwarding of API Gateway logs to CSOC | `bool` | `true` | no |
2020
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A map of default tags to apply to all taggable resources within the component | `map(string)` | `{}` | no |
2121
| <a name="input_disable_gateway_execute_endpoint"></a> [disable\_gateway\_execute\_endpoint](#input\_disable\_gateway\_execute\_endpoint) | Disable the execution endpoint for the API Gateway | `bool` | `true` | no |
22+
| <a name="input_download_url_ttl_seconds"></a> [download\_url\_ttl\_seconds](#input\_download\_url\_ttl\_seconds) | TTL in seconds for generated download URLs | `number` | `60` | no |
2223
| <a name="input_enable_alarms"></a> [enable\_alarms](#input\_enable\_alarms) | Enable CloudWatch alarms for this deployed environment | `bool` | `true` | no |
2324
| <a name="input_enable_api_data_trace"></a> [enable\_api\_data\_trace](#input\_enable\_api\_data\_trace) | Enable API Gateway data trace logging | `bool` | `false` | no |
2425
| <a name="input_enable_backups"></a> [enable\_backups](#input\_enable\_backups) | Enable backups | `bool` | `false` | no |
@@ -33,14 +34,18 @@ No requirements.
3334
| <a name="input_eventpub_data_plane_bus_arn"></a> [eventpub\_data\_plane\_bus\_arn](#input\_eventpub\_data\_plane\_bus\_arn) | ARN of the EventBridge data plane bus for eventpub | `string` | `""` | no |
3435
| <a name="input_force_destroy"></a> [force\_destroy](#input\_force\_destroy) | Flag to force deletion of S3 buckets | `bool` | `false` | no |
3536
| <a name="input_force_lambda_code_deploy"></a> [force\_lambda\_code\_deploy](#input\_force\_lambda\_code\_deploy) | If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development | `bool` | `false` | no |
36-
| <a name="input_group"></a> [group](#input\_group) | The group variables are being inherited from (often synonmous with account short-name) | `string` | n/a | yes |
37+
| <a name="input_group"></a> [group](#input\_group) | The account group short-name | `string` | n/a | yes |
3738
| <a name="input_kms_deletion_window"></a> [kms\_deletion\_window](#input\_kms\_deletion\_window) | When a kms key is deleted, how long should it wait in the pending deletion state? | `string` | `"30"` | no |
3839
| <a name="input_letter_event_source"></a> [letter\_event\_source](#input\_letter\_event\_source) | Source value to use for the letter status event updates | `string` | `"/data-plane/supplier-api/nhs-supplier-api-prod/main/update-status"` | no |
40+
| <a name="input_letter_queue_ttl_hours"></a> [letter\_queue\_ttl\_hours](#input\_letter\_queue\_ttl\_hours) | TTL in hours for letter queue records | `number` | `168` | no |
41+
| <a name="input_letter_queue_visibility_timeout"></a> [letter\_queue\_visibility\_timeout](#input\_letter\_queue\_visibility\_timeout) | Visibility timeout in seconds for processing queued letter updates | `number` | `300` | no |
3942
| <a name="input_letter_table_ttl_hours"></a> [letter\_table\_ttl\_hours](#input\_letter\_table\_ttl\_hours) | Number of hours to set as TTL on letters table | `number` | `24` | no |
43+
| <a name="input_letter_ttl_hours"></a> [letter\_ttl\_hours](#input\_letter\_ttl\_hours) | TTL in hours for letter records | `number` | `12960` | no |
4044
| <a name="input_log_level"></a> [log\_level](#input\_log\_level) | The log level to be used in lambda functions within the component. Any log with a lower severity than the configured value will not be logged: https://docs.python.org/3/library/logging.html#levels | `string` | `"INFO"` | no |
4145
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite | `number` | `0` | no |
4246
| <a name="input_manually_configure_mtls_truststore"></a> [manually\_configure\_mtls\_truststore](#input\_manually\_configure\_mtls\_truststore) | Manually manage the truststore used for API Gateway mTLS (e.g. for prod environment) | `bool` | `false` | no |
4347
| <a name="input_max_get_limit"></a> [max\_get\_limit](#input\_max\_get\_limit) | Default limit to apply to GET requests that support pagination | `number` | `2500` | no |
48+
| <a name="input_mi_ttl_hours"></a> [mi\_ttl\_hours](#input\_mi\_ttl\_hours) | TTL in hours for MI records | `number` | `2160` | no |
4449
| <a name="input_parent_acct_environment"></a> [parent\_acct\_environment](#input\_parent\_acct\_environment) | Name of the environment responsible for the acct resources used, affects things like DNS zone. Useful for named dev environments | `string` | `"main"` | no |
4550
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |
4651
| <a name="input_region"></a> [region](#input\_region) | The AWS Region | `string` | n/a | yes |

infrastructure/terraform/components/api/locals.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ locals {
2323

2424
common_lambda_env_vars = {
2525
APIM_CORRELATION_HEADER = "nhsd-correlation-id",
26-
DOWNLOAD_URL_TTL_SECONDS = 60
27-
EVENT_SOURCE = "/data-plane/supplier-api/${var.group}/${var.environment}/letters"
28-
LETTER_TTL_HOURS = 12960, # 18 months * 30 days * 24 hours
26+
DOWNLOAD_URL_TTL_SECONDS = var.download_url_ttl_seconds,
27+
EVENT_SOURCE = "/data-plane/supplier-api/${var.group}/${var.environment}/letters",
28+
LETTER_TTL_HOURS = var.letter_ttl_hours,
2929
LETTER_QUEUE_TABLE_NAME = aws_dynamodb_table.letter_queue.name,
30-
LETTER_QUEUE_TTL_HOURS = 168 # 7 days * 24 hours
31-
LETTER_QUEUE_VISIBILITY_TIMEOUT = 300, # 5 minutes * 60 seconds
30+
LETTER_QUEUE_TTL_HOURS = var.letter_queue_ttl_hours,
31+
LETTER_QUEUE_VISIBILITY_TIMEOUT = var.letter_queue_visibility_timeout,
3232
LETTERS_TABLE_NAME = aws_dynamodb_table.letters.name,
3333
MI_TABLE_NAME = aws_dynamodb_table.mi.name,
34-
MI_TTL_HOURS = 2160 # 90 days * 24 hours
34+
MI_TTL_HOURS = var.mi_ttl_hours,
3535
SNS_TOPIC_ARN = "${module.eventsub.sns_topic.arn}",
3636
SUPPLIER_CONFIG_TABLE_NAME = aws_dynamodb_table.supplier-configuration.name,
3737
SUPPLIER_QUOTAS_TABLE_NAME = aws_dynamodb_table.supplier-quotas.name,

infrastructure/terraform/components/api/variables.tf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ variable "region" {
2424

2525
variable "group" {
2626
type = string
27-
description = "The group variables are being inherited from (often synonmous with account short-name)"
27+
description = "The account group short-name"
2828
}
2929

3030
##
@@ -111,6 +111,36 @@ variable "max_get_limit" {
111111
default = 2500
112112
}
113113

114+
variable "download_url_ttl_seconds" {
115+
type = number
116+
description = "TTL in seconds for generated download URLs"
117+
default = 60
118+
}
119+
120+
variable "letter_ttl_hours" {
121+
type = number
122+
description = "TTL in hours for letter records"
123+
default = 12960
124+
}
125+
126+
variable "letter_queue_ttl_hours" {
127+
type = number
128+
description = "TTL in hours for letter queue records"
129+
default = 168
130+
}
131+
132+
variable "letter_queue_visibility_timeout" {
133+
type = number
134+
description = "Visibility timeout in seconds for processing queued letter updates"
135+
default = 300
136+
}
137+
138+
variable "mi_ttl_hours" {
139+
type = number
140+
description = "TTL in hours for MI records"
141+
default = 2160
142+
}
143+
114144
variable "parent_acct_environment" {
115145
type = string
116146
description = "Name of the environment responsible for the acct resources used, affects things like DNS zone. Useful for named dev environments"

0 commit comments

Comments
 (0)