diff --git a/test/index.test.ts b/test/index.test.ts index 3435da0..9bf188d 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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, @@ -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"]}}', }), ); @@ -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', + }), + ); +});