Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ test-features-integration: check-warn ## Run the BDD feature tests in the integr
--define="env=$(TF_WORKSPACE_NAME)" \
--define="account_name=$(ENV)" \
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
--define="host=$(HOST)" \
$(FEATURE_TEST_ARGS)

integration-test-with-custom_tag:
Expand All @@ -114,6 +115,7 @@ integration-test-with-custom_tag:
--define="env=$(TF_WORKSPACE_NAME)" \
--define="account_name=$(ENV)" \
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
--define="host=$(HOST)" \
$(FEATURE_TEST_ARGS)

test-features-integration-report: check-warn ## Run the BDD feature tests in the integration environment and generate allure report therafter
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ To run all the feature integration tests and generate an interactive Allure repo
make test-features-integration-report
```

#### Persistent environment testing

To run feature tests against a persistent environment:

1. Select the appropriate Terraform workspace, ensure you are logged in the AWS mgmt account (see `terraform/infrastructure/README.md`), for example to test the `qa-1` environment:

```
cd terraform/infrastructure
make ENV=qa TF_WORKSPACE_NAME=qa-1 init
cd ../..
```

2. Switch to the relevant AWS account (e.g., test), then run:

```
make ENV=qa TF_WORKSPACE_NAME=qa-1 HOST=qa-1.qa.record-locator.national.nhs.uk test-features-integration
```

### Debugging Behave Integration Tests in VS Code

Integration tests can be debugged directly in **VS Code** using a launch configuration. Instructions on how to set this up for the first time and run the debugger are below.
Expand Down
4 changes: 3 additions & 1 deletion terraform/infrastructure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ This project has a number of "persistent environments", similar to traditional d
| qa-sandbox | qa-sandbox-N | `etc/qa.tfvars` | test | `qa.record-locator.national.nhs.uk` | `internal-qa-sandbox.api.service.nhs.uk` |
| int | int-N | `etc/int.tfvars` | test | `record-locator.int.national.nhs.uk` | `int.api.service.nhs.uk` |
| sandbox | int-sandbox-N | `etc/int.tfvars` | test | `record-locator.int.national.nhs.uk` | `sandbox.api.service.nhs.uk` |
| perftest | perftest-N | `etc/perftest.tfvars` | test | `perftest.record-locator.national.nhs.uk` | `perftest.api.service.nhs.uk` |
| perftest | perftest-N | `etc/perftest.tfvars` | test | `perftest.record-locator.national.nhs.uk` | `internal-qa.api.service.nhs.uk` |
| ref | ref-N | `etc/ref.tfvars` | test | `record-locator.ref.national.nhs.uk` | `ref.api.service.nhs.uk` |
| prod | prod-N | `etc/prod.tfvars` | prod | `record-locator.national.nhs.uk` | `api.service.nhs.uk` |

The `N` in the TF workspace name repesents the stack id in that environment. So, for example, the internal-dev environment might have two stacks, `dev-1` and `dev-2` with TF workspace names matching their stack names. All resources for the `dev-1` stack will be contained within the `dev-1` TF workspace.

CI pipeline creates infrastructure in the dev AWS account. These will have workspace id of `nrl<jira-id>-<first six char of commit hash>` and use variables in `etc/dev.tfvars`

Please note: There is currently no dedicated APIGEE proxy for the perftest environment. As a temporary measure, `internal-qa.api.service.nhs.uk` points to perftest. You can switch the `internal-qa` APIGEE proxy between QA and perftest by running the `persistent environment deploy` or `switch active stack` GitHub Actions.

## Table of Contents

1. [Prerequisites](#prerequisites)
Expand Down
9 changes: 6 additions & 3 deletions tests/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ def before_all(context: Context):

context.env = context.config.userdata.get("env")
context.account_name = context.config.userdata.get("account_name")
context.is_shared_resources = context.config.userdata.get("is_shared_resources")
context.use_shared_resources = context.config.userdata.get("use_shared_resources")
context.host = context.config.userdata.get(
"host", f"https://{context.env}.api.record-locator.dev.national.nhs.uk/"
)

context.stack_name = (
context.account_name if context.is_shared_resources else context.env
context.account_name if context.use_shared_resources else context.env
)

context.base_url = f"https://{context.env}.api.record-locator.dev.national.nhs.uk/"
context.base_url = f"https://{context.host}/"
context.request_id = "feature-test-request-id"
context.correlation_id = "feature-test-correlation-id"

Expand Down
24 changes: 13 additions & 11 deletions tests/features/utils/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ def get_cert_path_for_environment(environment: Optional[str]) -> Tuple[str, str]
if not environment:
raise ValueError("Environment (env) not provided")

cert_path: Optional[Path] = None
key_path: Optional[Path] = None

match environment:
case "dev":
cert_path = CLIENT_CERT_PATH / "dev.crt"
key_path = CLIENT_CERT_PATH / "dev.key"

case _:
cert_path = CLIENT_CERT_PATH / "dev.crt"
key_path = CLIENT_CERT_PATH / "dev.key"
# List only non-sandbox environments
# Sandbox uses the same certs as their non-sandbox equivalents.
ENVIRONMENTS = ["dev", "qa", "int", "ref", "perftest", "prod"]

selected_env = "dev" # default to dev (e.g: ci environments)
for env in ENVIRONMENTS:
# match dev-1, qa-2, etc. it works for sandbox too
if environment == env or environment.startswith(f"{env}-"):
selected_env = env
break

cert_path = CLIENT_CERT_PATH / f"{selected_env}.crt"
key_path = CLIENT_CERT_PATH / f"{selected_env}.key"

if not cert_path.exists() or not key_path.exists():
raise FileNotFoundError(
Expand Down
Loading