Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use aws-cdk-lib/assertions #1372

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-singers-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

template/lambda-sqs-worker-cdk: Switch to `aws-cdk-lib/assertions`
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

exports[`returns expected CloudFormation stack for dev 1`] = `
{
"Parameters": {
"BootstrapVersion": {
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]",
"Type": "AWS::SSM::Parameter::Value<String>",
},
},
"Resources": {
"kmskey49FBC3B3": {
"DeletionPolicy": "Retain",
Expand Down Expand Up @@ -358,11 +365,45 @@ exports[`returns expected CloudFormation stack for dev 1`] = `
"UpdateReplacePolicy": "Delete",
},
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5",
],
{
"Ref": "BootstrapVersion",
},
],
},
],
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.",
},
],
},
},
}
`;

exports[`returns expected CloudFormation stack for prod 1`] = `
{
"Parameters": {
"BootstrapVersion": {
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]",
"Type": "AWS::SSM::Parameter::Value<String>",
},
},
"Resources": {
"kmskey49FBC3B3": {
"DeletionPolicy": "Retain",
Expand Down Expand Up @@ -719,5 +760,32 @@ exports[`returns expected CloudFormation stack for prod 1`] = `
"UpdateReplacePolicy": "Delete",
},
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5",
],
{
"Ref": "BootstrapVersion",
},
],
},
],
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.",
},
],
},
},
}
`;
6 changes: 4 additions & 2 deletions template/lambda-sqs-worker-cdk/infra/appStack.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SynthUtils } from '@aws-cdk/assert';
import { App } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';

import cdkJson from '../cdk.json';

Expand All @@ -24,7 +24,9 @@ it.each(contexts)(

const stack = new AppStack(app, 'appStack');

const json = JSON.stringify(SynthUtils.toCloudFormation(stack)).replace(
const template = Template.fromStack(stack);

const json = JSON.stringify(template.toJSON()).replace(
/"S3Key":"([0-9a-f]+)\.zip"/g,
(_, hash) => `"S3Key":"${'x'.repeat(hash.length)}.zip"`,
);
Expand Down
1 change: 0 additions & 1 deletion template/lambda-sqs-worker-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"zod": "^3.19.1"
},
"devDependencies": {
"@aws-cdk/assert": "^2.24.0",
"@types/aws-lambda": "^8.10.82",
"@types/node": "^20.9.0",
"aws-cdk": "^2.109.0",
Expand Down
Loading