Skip to content

Commit

Permalink
Newer template
Browse files Browse the repository at this point in the history
  • Loading branch information
flurdy committed Nov 28, 2024
1 parent 982aa0d commit 5d51f15
Show file tree
Hide file tree
Showing 16 changed files with 436 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/allure-results
/allure-report
/docker
35 changes: 35 additions & 0 deletions .github/workflows/journey-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run Journey Tests on GitHub

permissions:
checks: write
pull-requests: write

on:
workflow_dispatch:
workflow_call:
jobs:
build:
name: run-tests
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Setup the tests
run: npm i
- name: Start docker compose
run: docker compose up --wait-timeout 300 -d --quiet-pull
- name: Run the tests
run: |
npm run test:github
npm run report
- name: debug
if: failure()
run: |
docker compose logs > logs.txt
docker ps
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
package-lock.json
node_modules
docker
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ The following attribution statement MUST be cited in your products and applicati

> Contains public sector information licensed under the Open Government licence v3
## Running on GitHub

Alternatively you can run the test suite as a GitHub workflow.
Test runs on GitHub are not able to connect to the CDP Test environments. Instead, they run the tests agains a version of the services running in docker.
A docker compose `compose.yml` is included as a starting point, which includes the databases (mongodb, redis) and infrastructure (localstack) pre-setup.

Steps:

1. Edit the compose.yml to include your services.
2. Modify the scripts in docker/scripts to pre-populate the database, if required and create any localstack resources.
3. Test the setup locally with `docker compose up` and `npm run test:github`
4. Set up the workflow trigger in `.github/workflows/journey-tests`.

By default, the provided workflow will run when triggered manually from GitHub or when triggered by another workflow.

If you want to use the repository exclusively for running docker composed based test suites consider displaying the publish.yml workflow.

### About the licence

The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable
Expand Down
108 changes: 108 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
################################################################################
# Docker Compose file for starting up the service for testing in GitHub workflow
# This template provides comparable infrastructure to the real environment.
# - mongodb
# - redis
# - localstack (s3, sqs, sns)
#
# Both mongo and localstack have init scripts included for setting up resources
# on startup. These scripts are in docker/scripts.
#
# It also includes a selenium-chrome container for running the browser headless.
#
# The services being tested can either be started up here using the latest
# builds from dockerhub.
# In the example each service has a .env config file in docker/config/
# Services can reference each other by their container names.
# e.g. http://cdp-example-node-backend:3001/
#
################################################################################
services:

################################################################################
# Headless browser, used by the test suite to actually run the tests against the
# containers.
selenium-chrome:
image: selenium/standalone-chrome:latest
ports:
- 4444:4444

################################################################################
mongodb:
image: mongo:6
volumes:
- ./docker/scripts/mongodb:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.hello().ok"]
interval: 5s
start_period: 5s
retries: 3
################################################################################
localstack:
image: localstack/localstack:3.2.0
environment:
- LOCALSTACK_HOST=127.0.0.1
- SERVICES=s3,sqs,sns,dynamodb
- LS_LOG=WARN
env_file:
- ./docker/config/defaults.env
volumes:
- ./docker/scripts/localstack:/etc/localstack/init/ready.d
healthcheck:
test: ["CMD", "curl", "localhost:4566"]
interval: 5s
start_period: 5s
retries: 3

################################################################################
redis:
image: redis:7
restart: always
healthcheck:
test: [ "CMD", "redis-cli", "PING" ]
interval: 5s
start_period: 2s
retries: 5


################################################################################
#
# Add the services you want to test below.
#
################################################################################
# cdp-example-node-frontend:
# image: defradigital/cdp-example-node-frontend:latest
# env_file:
# - ./docker/config/defaults.env
# - ./docker/config/example-frontend.env
# environment:
# - PORT=3000
# depends_on:
# cdp-example-node-backend:
# condition: service_started
# redis:
# condition: service_healthy
# ports:
# - 3000:3000
# healthcheck:
# test: ["CMD", "curl", "http://localhost:3000/health"]
# interval: 3s
# start_period: 2s
# retries: 3

################################################################################
# cdp-example-node-backend:
# image: defradigital/cdp-example-node-backend:latest
# env_file:
# - ./docker/config/defaults.env
# - ./docker/config/example-backend.env
# environment:
# - PORT=3001
# depends_on:
# mongodb:
# condition: service_healthy
# healthcheck:
# test: ["CMD", "curl", "http://localhost:3001/health"]
# interval: 3s
# start_period: 2s
# retries: 3
21 changes: 21 additions & 0 deletions docker/config/defaults.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MongoDB
MONGO_URI=mongodb://mongodb:27017/?tls=false
Mongo__DatabaseUri=mongodb://mongodb:27017/?tls=false

# Redis
REDIS_HOST=redis
USE_SINGLE_INSTANCE_CACHE=true

# Localstack/AWS
LOCALSTACK_URL=http://localstack:4566
SNS_ENDPOINT=http://localstack:4566
SQS_ENDPOINT=http://localstack:4566
S3_ENDPOINT=http://localstack:4566

AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
AWS_SECRET_KEY=test
AWS_REGION=eu-west-2

# Placeholder trust store cert
TRUSTSTORE_CDP_ROOT_CA=LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUI5akNDQVYrZ0F3SUJBZ0lVS1I4MkxndGtOQmNjZHlwWUQyNks4N3paK3ZZd0RRWUpLb1pJaHZjTkFRRUUKQlFBd0RURUxNQWtHQTFVRUN3d0NSVkF3SGhjTk1Ua3dPVEkyTURJd05EVXlXaGNOTVRreE1ESTJNREl3TkRVeQpXakFOTVFzd0NRWURWUVFMREFKRlVEQ0JuekFOQmdrcWhraUc5dzBCQVFFRkFBT0JqUUF3Z1lrQ2dZRUF3S3ZhCk5aQ09HY3VZOTAvQnVkUytxUWljK0EzMXVNOG1MdG1JNjBSMWlFamdFV0dCQ3hTaURiMmg4bVFKaVh3a3VsOVcKZWJhYXpQN2hrcWtkTm9KZ1YvNk5FNysrR0t5eVM4ZkloSmdlV1NiNkVlbE1GaGpRMG5aS3piWlg1bXMzSTkxbgp0d3prY0h0S0NRaS9naS9Sb3VobGsvUC9RVmNyelNnSFVIcUpOeTBDQXdFQUFhTlRNRkV3SFFZRFZSME9CQllFCkZISGJncW5uaG0zR0FKNGd5Mkl1RUR4cEx5ZTdNQjhHQTFVZEl3UVlNQmFBRkhIYmdxbm5obTNHQUo0Z3kySXUKRUR4cEx5ZTdNQThHQTFVZEV3RUIvd1FGTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVFQlFBRGdZRUFHNUNvcWNFeQoxNXZVcGo1VmZKZVIvRFM3MHRQSWlucC9UQ0M5a1JPLysrVFNuUGJxVmNmUHI4dkl5YzRMM01QS2pYRkJzZWZFCnZ0ZkhHR3VjVnR2NU4xKzRVL2I5TnhORmJ1SDJNUDdXM3N3WjRXTTcyTmErVzZpT2h3ZXNPcjBwM0ljT2Z4YzMKUk5DbmFnRm10YkRGeEFsUFhRMGQrbStONWd4TFJvQ1gxaEU9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
1 change: 1 addition & 0 deletions docker/config/example-backend.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
S3_BUCKET=test-bucket
1 change: 1 addition & 0 deletions docker/config/example-frontend.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXAMPLE_BACKEND_URL=http://example-node-backend:3001
Empty file.
6 changes: 6 additions & 0 deletions docker/scripts/localstack/10-setup-buckets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# This is an example of how to setup localstack resources on startup.
# Uncomment the below to create a localstack S3 bucket called 'example-bucket'

# aws --endpoint-url=$LOCALSTACK_URL s3 --region $AWS_REGION mb s3://example-bucket
Empty file added docker/scripts/mongodb/.gitkeep
Empty file.
7 changes: 7 additions & 0 deletions docker/scripts/mongodb/10-database-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Mongodb script for inserting test data into the docker-compose mongo instance
*/

db = db.getSiblingDB('test')

db.test.insertOne({ test: 'data' })
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"components/*": ["./test/components/*"]
}
},
"exclude": ["node_modules", "build"]
"exclude": ["node_modules", "build", "docker"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@wdio/local-runner": "8.35.1",
"@wdio/mocha-framework": "8.35.0",
"@wdio/spec-reporter": "8.32.4",
"@wdio/junit-reporter": "9.2.14",
"allure-commandline": "2.27.0",
"babel-plugin-module-resolver": "5.0.0"
},
Expand Down
4 changes: 3 additions & 1 deletion wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ export const config = {
context,
{ error, result, duration, passed, retries }
) {
await browser.takeScreenshot()
if (error) {
await browser.takeScreenshot()
}
},

/**
Expand Down
Loading

0 comments on commit 5d51f15

Please sign in to comment.