Skip to content

Commit

Permalink
Merge pull request #1 from DEFRA/environment-config
Browse files Browse the repository at this point in the history
Environment config
  • Loading branch information
flurdy committed May 15, 2024
2 parents 6cd6a88 + 8380633 commit e2f8ca0
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 8 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ Run smoke tests against the `CDP Uploader`.
- [Node.js](#nodejs)
- [Local](#local)
- [Setup](#setup)
- [Local config](#local-config)
- [Running tests](#running-tests)
- [Production](#production)
- [Generate report](#report)
- [Production](#environment-production)
- [Environment config](#config)
- [Requirements of CDP Environment Tests](#requirements-of-cdp-environment-tests)
- [Licence](#licence)
- [About the licence](#about-the-licence)
Expand All @@ -22,6 +25,17 @@ Install application dependencies:
npm install
```

### Local config

Set local environment variables

```bash
export UPLOADER_BUCKET=my-bucket
export CDP_UPLOADER_BASE_URL=http://localhost:7337
```

_E.g. [direnv.net](https://direnv.net/)_

### Running tests

Start application you are testing on the url specified in a `baseUrl` in `src/config/index.js`
Expand All @@ -32,12 +46,37 @@ npm run test

### Reports

Generate report

```bash
npm run report
```

View report

```bash
open allure-results/index.html
```

## Production

### Environment Config

As the environment runner is isolated it does not get injected with `cdp-app-config`
so the environment variables are set `~/src/config/index.js`.

`CDP_UPLOADER_BASE_URL` is assumed to be

```
https://cdp-uploader.${process.env.ENVIRONMENT}.cdp-int.defra.cloud
```

Whilst the `UPLOADER_BUCKET` is hardcoded per environment underneath

```
s3UploadBucket.environments: {}
```

### Running the tests

Tests are run from the CDP-Portal under the Test Suites section. Before any changes can be run, a new docker image must be built, this will happen automatically when a pull request is merged into the `main` branch.
Expand Down
32 changes: 26 additions & 6 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,34 @@ const config = convict({
uploaderBaseUrl: {
doc: 'Uploader Base URL',
format: String,
default: 'http://localhost:7337',
default: process.env.ENVIRONMENT
? `https://cdp-uploader.${process.env.ENVIRONMENT}.cdp-int.defra.cloud`
: null,
nullable: false,
env: 'CDP_UPLOADER_BASE_URL'
},
smokeTestBucket: {
doc: 'S3 bucket for test uploads',
format: String,
default: 'cdp-uploader-smoke-test-bucket',
env: 'UPLOADER_SMOKE_TEST_BUCKET'
s3UploadBucket: {
bucket: {
doc: 'S3 bucket for uploads',
format: String,
default: null,
nullable: process.env.ENVIRONMENT && process.env.ENVIRONMENT !== 'local',
env: 'UPLOADER_BUCKET'
},
environments: {
'infra-dev': {
doc: 'S3 bucket for uploads in infra-dev',
format: String,
default: 'cdp-infra-dev-cdp-example-node-frontend-f5a9fee866ed',
env: 'UPLOADER_BUCKET_INFRA_DEV'
},
dev: {
doc: 'S3 bucket for uploads in dev',
format: String,
default: 'cdp-dev-cdp-example-node-frontend-9954cf787c89',
env: 'UPLOADER_BUCKET_DEV'
}
}
},
smokeTestPath: {
doc: 'S3 prefix path for test uploads',
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/upload-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {
uploadFile,
uploadStatus
} from '~/src/helpers/uploader-fetch'
import { uploaderBucket } from '~/src/helpers/uploader-bucket'

const pollInterval = config.get('uploadScanInterval')
const maxAttempts = config.get('uploadMaxAttempts')
const cleanFilename = config.get('cleanFileName')
const virusFilename = config.get('virusFileName')
const destinationBucket = config.get('smokeTestBucket')
const destinationBucket = uploaderBucket()
const destinationPath = config.get('smokeTestPath')
const redirectUrl = config.get('redirectUrl')
const initiatePayload = {
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/uploader-bucket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { config } from '~/src/config'

const envVarBucket = config.get('s3UploadBucket.bucket')
const environment = process.env.ENVIRONMENT

function uploaderBucket() {
if (envVarBucket) {
return envVarBucket
}
if (environment) {
return config.get(`s3UploadBucket.environments.${environment}`)
}
throw new Error('No bucket found')
}

export { uploaderBucket }

0 comments on commit e2f8ca0

Please sign in to comment.