Skip to content

Commit

Permalink
More construct tests (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog authored Mar 3, 2020
1 parent 32b81b5 commit 79cd9f2
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { expect, haveResource } from '@aws-cdk/assert';
import { Stack } from '@aws-cdk/core';
import '@aws-cdk/assert/jest';
import { SopsSecretsManager } from '..';
import * as secretsManager from '@aws-cdk/aws-secretsmanager';

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

new SopsSecretsManager(stack, 'Secret', {
const secretValues = new SopsSecretsManager(stack, 'SecretValues', {
secretName: 'MySecret',
path: './test/test.yaml',
kmsKey: undefined,
Expand All @@ -19,6 +20,7 @@ test('creates-a-provider', () => {

expect(stack).to(
haveResource('Custom::SopsSecretsManager', {
SecretArn: stack.resolve((secretValues.secret as secretsManager.Secret).secretArn),
Mappings: '{"mykey":{"path":["a","b"]}}',
}),
);
Expand All @@ -29,3 +31,35 @@ test('creates-a-provider', () => {
}),
);
});

test('uses a secret, creates a custom resource', () => {
const stack = new Stack();

const secret = new secretsManager.Secret(stack, 'Secret', {
secretName: 'MySecret',
});

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

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

expect(stack).to(
haveResource('AWS::SecretsManager::Secret', {
Name: 'MySecret',
}),
);
});

0 comments on commit 79cd9f2

Please sign in to comment.