Skip to content

Commit

Permalink
chore: sanitize awscdk snapshot tests and cleanup cdktf snapshots (#3826
Browse files Browse the repository at this point in the history
)

fixes #3812 

- remove path-dependent hashes for awscdk like we do for cdktf tests
- change tfSanitize to return an object instead of a string, this results in much nicer looking snapshots for cdktf snapshots (less escapes)

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
MarkMcCulloh authored Aug 15, 2023
1 parent cff291a commit 672baf4
Show file tree
Hide file tree
Showing 33 changed files with 4,026 additions and 4,012 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def submit_response(event: dict, context, response_status: str, error_message: s
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b9deba0f7dc17e61cf9f7e0fa901af6e57ec811a13882b7048ee9aa75797378d.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -722,7 +722,7 @@ def submit_response(event: dict, context, response_status: str, error_message: s
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b9deba0f7dc17e61cf9f7e0fa901af6e57ec811a13882b7048ee9aa75797378d.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -1095,7 +1095,7 @@ def submit_response(event: dict, context, response_status: str, error_message: s
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b9deba0f7dc17e61cf9f7e0fa901af6e57ec811a13882b7048ee9aa75797378d.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -1446,7 +1446,7 @@ def submit_response(event: dict, context, response_status: str, error_message: s
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b9deba0f7dc17e61cf9f7e0fa901af6e57ec811a13882b7048ee9aa75797378d.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -1547,7 +1547,7 @@ exports[`bucket with two preflight objects 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "2bc265c5e0569aeb24a6349c15bd54e76e845892376515e036627ab0cc70bb64.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Layers": [
Expand Down Expand Up @@ -1757,7 +1757,7 @@ exports[`bucket with two preflight objects 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "f8e422c63159c82c409e8254300a3134e020892c27382902d4c8c0a5b35d0a06.zip",
"S3Key": "<S3Key>",
},
"Description": "/opt/awscli/aws",
},
Expand Down Expand Up @@ -1797,7 +1797,7 @@ exports[`bucket with two preflight objects 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "f8e422c63159c82c409e8254300a3134e020892c27382902d4c8c0a5b35d0a06.zip",
"S3Key": "<S3Key>",
},
"Description": "/opt/awscli/aws",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ exports[`dec() policy statement 2`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "f3738bcfd58c05cf71242945f065454f27590bcdafb0ccd96150f36963676a16.zip",
"S3Key": "<S3Key>",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -367,7 +367,7 @@ exports[`function with a counter binding 2`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b03ff20bc0f7d7c4d3c6ac541eb138884f06868c5412ad8414d7913bebca1b6d.zip",
"S3Key": "<S3Key>",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -539,7 +539,7 @@ exports[`inc() policy statement 2`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "b03ff20bc0f7d7c4d3c6ac541eb138884f06868c5412ad8414d7913bebca1b6d.zip",
"S3Key": "<S3Key>",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -711,7 +711,7 @@ exports[`peek() policy statement 2`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "9189a03759b8a966a3e4efb03da3bf6b2546b25b85ccf726d3240bbc1b86e272.zip",
"S3Key": "<S3Key>",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -883,7 +883,7 @@ exports[`set() policy statement 2`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "0da3747a941f72aa30762d828c78b18e9f513c3801f61711ae0fd3ff29a218b5.zip",
"S3Key": "<S3Key>",
},
"Environment": {
"Variables": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports[`basic function 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "34031e10a718327bb9ec731d7b54025eebeef68c03bb4f5a3d8e6ad5262a0517.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -124,7 +124,7 @@ exports[`basic function with environment variables 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "34031e10a718327bb9ec731d7b54025eebeef68c03bb4f5a3d8e6ad5262a0517.zip",
"S3Key": "<S3Key>",
},
"Environment": {
"Variables": {
Expand Down Expand Up @@ -230,7 +230,7 @@ exports[`basic function with memory size specified 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "34031e10a718327bb9ec731d7b54025eebeef68c03bb4f5a3d8e6ad5262a0517.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"MemorySize": 512,
Expand Down Expand Up @@ -331,7 +331,7 @@ exports[`basic function with timeout explicitly set 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "34031e10a718327bb9ec731d7b54025eebeef68c03bb4f5a3d8e6ad5262a0517.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports[`queue with a consumer function 2`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "a028d8321beb7aea3bd17a266a795b276daefdce58f7b21e35e64db6463e08bc.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exports[`schedule behavior with cron 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "99cc55258c346f62db746a74a3b335f909d0326a46c142758fdf8f8d189b2678.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -198,7 +198,7 @@ exports[`schedule behavior with rate 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "99cc55258c346f62db746a74a3b335f909d0326a46c142758fdf8f8d189b2678.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -363,7 +363,7 @@ exports[`schedule with two functions 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "99cc55258c346f62db746a74a3b335f909d0326a46c142758fdf8f8d189b2678.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -417,7 +417,7 @@ exports[`schedule with two functions 1`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "99cc55258c346f62db746a74a3b335f909d0326a46c142758fdf8f8d189b2678.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ exports[`topic with multiple subscribers 3`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "4ab62cb5f98ad2f9b2b3dd82c783136bb4211456f7f49afad99a73e6c40a7e6a.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -191,7 +191,7 @@ exports[`topic with multiple subscribers 3`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "f13044b492c96c95c553740c33ce68a00d453711d947fd68ff5ed4ac51e58c34.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -340,7 +340,7 @@ exports[`topic with subscriber function 2`] = `
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
},
"S3Key": "2ec978de802295e114de200ac50fa06d9a5236c445ecf719650e5f86f9ba6c87.zip",
"S3Key": "<S3Key>",
},
"Handler": "index.handler",
"Role": {
Expand Down
17 changes: 9 additions & 8 deletions libs/wingsdk/test/target-awscdk/bucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { test, expect } from "vitest";
import { Bucket } from "../../src/cloud";
import * as awscdk from "../../src/target-awscdk";
import { Testing } from "../../src/testing";
import { mkdtemp } from "../util";
import { mkdtemp, awscdkSanitize } from "../util";

const CDK_APP_OPTS = {
stackName: "my-project",
entrypointDir: __dirname,
};

test("create a bucket", async () => {
Expand All @@ -28,7 +29,7 @@ test("create a bucket", async () => {
},
})
);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("bucket is public", () => {
Expand All @@ -40,7 +41,7 @@ test("bucket is public", () => {
// THEN
const template = Template.fromJSON(JSON.parse(output));
template.resourceCountIs("AWS::S3::Bucket", 1);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("bucket with two preflight objects", () => {
Expand All @@ -54,7 +55,7 @@ test("bucket with two preflight objects", () => {
// THEN
const template = Template.fromJSON(JSON.parse(output));
template.resourceCountIs("Custom::CDKBucketDeployment", 2);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("bucket with onCreate method", () => {
Expand Down Expand Up @@ -86,7 +87,7 @@ async handle(event) {
},
})
);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("bucket with onDelete method", () => {
Expand Down Expand Up @@ -118,7 +119,7 @@ async handle(event) {
},
})
);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("bucket with onUpdate method", () => {
Expand Down Expand Up @@ -150,7 +151,7 @@ async handle(event) {
},
})
);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("bucket with onEvent method", () => {
Expand Down Expand Up @@ -182,5 +183,5 @@ async handle(event) {
},
})
);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});
17 changes: 9 additions & 8 deletions libs/wingsdk/test/target-awscdk/counter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { test, expect } from "vitest";
import { Counter, Function, CounterInflightMethods } from "../../src/cloud";
import * as awscdk from "../../src/target-awscdk";
import { Testing } from "../../src/testing";
import { sanitizeCode, mkdtemp } from "../util";
import { sanitizeCode, mkdtemp, awscdkSanitize } from "../util";

const CDK_APP_OPTS = {
stackName: "my-project",
entrypointDir: __dirname,
};

test("default counter behavior", () => {
Expand All @@ -23,7 +24,7 @@ test("default counter behavior", () => {
BillingMode: "PAY_PER_REQUEST",
})
);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("counter with initial value", () => {
Expand All @@ -42,7 +43,7 @@ test("counter with initial value", () => {
BillingMode: "PAY_PER_REQUEST",
})
);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("function with a counter binding", () => {
Expand Down Expand Up @@ -71,7 +72,7 @@ test("function with a counter binding", () => {
template.resourceCountIs("AWS::IAM::Role", 1);
template.resourceCountIs("AWS::IAM::Policy", 1);
template.resourceCountIs("AWS::Lambda::Function", 1);
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("inc() policy statement", () => {
Expand Down Expand Up @@ -106,7 +107,7 @@ test("inc() policy statement", () => {
]),
},
});
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("dec() policy statement", () => {
Expand Down Expand Up @@ -141,7 +142,7 @@ test("dec() policy statement", () => {
]),
},
});
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("peek() policy statement", () => {
Expand Down Expand Up @@ -176,7 +177,7 @@ test("peek() policy statement", () => {
]),
},
});
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});

test("set() policy statement", () => {
Expand Down Expand Up @@ -211,5 +212,5 @@ test("set() policy statement", () => {
]),
},
});
expect(template.toJSON()).toMatchSnapshot();
expect(awscdkSanitize(template)).toMatchSnapshot();
});
Loading

0 comments on commit 672baf4

Please sign in to comment.