Skip to content

Commit

Permalink
Tests for CDK construct
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog committed Mar 2, 2020
1 parent 51088ed commit a8ccf77
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
version: 2

jobs:
test-construct:
working_directory: ~/repo
docker:
- image: circleci/node:12
steps:
- checkout

- run:
name: update-npm
command: 'sudo npm install -g npm@latest'

- run: npm install

- run: npm run test

build:
working_directory: ~/repo
docker:
Expand Down Expand Up @@ -42,12 +57,17 @@ workflows:
version: 2
build-and-publish:
jobs:
- test-construct:
filters:
tags:
only: /\d+\.\d+\.\d+/
- build:
filters:
tags:
only: /\d+\.\d+\.\d+/
- publish:
requires:
- test-construct
- build
filters:
tags:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ build/
# No package-lock.json
package-lock.json

# Allow jest config
!jest.config.js

# Logs
logs
*.log
Expand Down
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
"roots": [
"<rootDir>/test"
],
testMatch: [ '**/*.test.ts'],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"secretsmanager"
],
"scripts": {
"test": "jest",
"get-sops": "wget https://github.com/mozilla/sops/releases/download/v3.5.0/sops-v3.5.0.linux -O ./provider/sops && chmod a+x ./provider/sops",
"tsc": "tsc",
"clean": "rm -rf build/",
Expand All @@ -40,6 +41,7 @@
"typescript": ">=3.0.0"
},
"devDependencies": {
"@aws-cdk/assert": "1.26.0",
"auto-changelog": "^1.16.2",
"@aws-cdk/aws-lambda": "^1.21.1",
"@aws-cdk/aws-iam": "^1.21.1",
Expand All @@ -50,6 +52,9 @@
"@aws-cdk/core": "^1.21.1",
"@aws-cdk/custom-resources": "^1.21.1",
"@aws-cdk/aws-cloudformation": "^1.21.1",
"typescript": ">=3.0.0"
"typescript": ">=3.0.0",
"jest": "24.9.0",
"ts-jest": "24.1.0",
"@types/jest": "~24.0.22"
}
}
31 changes: 31 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { Stack } from '@aws-cdk/core';
import '@aws-cdk/assert/jest';
import { SopsSecretsManager } from '..';

test('creates-a-provider', () => {
const stack = new Stack();

new SopsSecretsManager(stack, 'Secret', {
secretName: 'MySecret',
path: './test/test.yaml',
kmsKey: undefined,
mappings: {
mykey: {
path: ['a', 'b'],
},
},
});

expect(stack).to(
haveResource('Custom::SopsSecretsManager', {
Mappings: '{"mykey":{"path":["a","b"]}}',
}),
);

expect(stack).to(
haveResource('AWS::SecretsManager::Secret', {
Name: 'MySecret',
}),
);
});
1 change: 1 addition & 0 deletions test/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: test
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"experimentalDecorators": true,
"strictPropertyInitialization":false,
"typeRoots": ["./node_modules/@types"],
"types": ["node"]
"types": ["node", "jest"]
},
"include": [
"index.ts"
Expand Down

0 comments on commit a8ccf77

Please sign in to comment.