Skip to content

Commit

Permalink
test: fix not deterministic snapshot matching
Browse files Browse the repository at this point in the history
  • Loading branch information
floydspace committed Dec 17, 2023
1 parent 31dd88f commit 889524d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 43 deletions.
46 changes: 26 additions & 20 deletions e2e/__snapshots__/individually.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,6 @@ exports[`individually 6`] = `
},
"Type": "AWS::Lambda::Permission",
},
"Hello1LambdaVersionCSwh1ndXXWK0PuziFcAZEvHblwz5E8ZASq6DpWhA": {
"DeletionPolicy": "Retain",
"Properties": {
"CodeSha256": Any<String>,
"FunctionName": {
"Ref": "Hello1LambdaFunction",
},
},
"Type": "AWS::Lambda::Version",
},
"Hello1LogGroup": {
"Properties": {
"LogGroupName": "/aws/lambda/serverless-example-dev-hello1",
Expand Down Expand Up @@ -347,16 +337,6 @@ exports[`individually 6`] = `
},
"Type": "AWS::Lambda::Permission",
},
"Hello2LambdaVersionwMMe1vFJ1KSlA5MihlkJVM5uJp72R4R6u5Vtbnz3NSY": {
"DeletionPolicy": "Retain",
"Properties": {
"CodeSha256": Any<String>,
"FunctionName": {
"Ref": "Hello2LambdaFunction",
},
},
"Type": "AWS::Lambda::Version",
},
"Hello2LogGroup": {
"Properties": {
"LogGroupName": "/aws/lambda/serverless-example-dev-hello2",
Expand Down Expand Up @@ -528,3 +508,29 @@ exports[`individually 7`] = `
"Type": "AWS::ApiGateway::Deployment",
}
`;
exports[`individually 8`] = `
{
"DeletionPolicy": "Retain",
"Properties": {
"CodeSha256": Any<String>,
"FunctionName": {
"Ref": "Hello1LambdaFunction",
},
},
"Type": "AWS::Lambda::Version",
}
`;
exports[`individually 9`] = `
{
"DeletionPolicy": "Retain",
"Properties": {
"CodeSha256": Any<String>,
"FunctionName": {
"Ref": "Hello2LambdaFunction",
},
},
"Type": "AWS::Lambda::Version",
}
`;
23 changes: 13 additions & 10 deletions e2e/__snapshots__/minimal.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14269,16 +14269,6 @@ exports[`minimal 5`] = `
},
"Type": "AWS::Lambda::Permission",
},
"ValidateIsinLambdaVersionEpft2h1OOZyD03CU8JMaqcj3Xcth3KeWrSuKw8G2UQ": {
"DeletionPolicy": "Retain",
"Properties": {
"CodeSha256": Any<String>,
"FunctionName": {
"Ref": "ValidateIsinLambdaFunction",
},
},
"Type": "AWS::Lambda::Version",
},
"ValidateIsinLogGroup": {
"Properties": {
"LogGroupName": "/aws/lambda/minimal-example-dev-validateIsin",
Expand All @@ -14302,3 +14292,16 @@ exports[`minimal 6`] = `
"Type": "AWS::ApiGateway::Deployment",
}
`;

exports[`minimal 7`] = `
{
"DeletionPolicy": "Retain",
"Properties": {
"CodeSha256": Any<String>,
"FunctionName": {
"Ref": "ValidateIsinLambdaFunction",
},
},
"Type": "AWS::Lambda::Version",
}
`;
26 changes: 18 additions & 8 deletions e2e/individually.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ test('individually', () => {
s.startsWith('ApiGatewayDeployment')
) as keyof typeof cloudformation.Resources;

const { [apiGatewayDeploymentPropertyKey]: apiGatewayDeployment, ...deterministicResources } =
cloudformation.Resources;
const hello1LambdaVersionPropertyKey = cloudformation.Outputs.Hello1LambdaFunctionQualifiedArn.Value
.Ref as keyof typeof cloudformation.Resources;

const hello2LambdaVersionPropertyKey = cloudformation.Outputs.Hello2LambdaFunctionQualifiedArn.Value
.Ref as keyof typeof cloudformation.Resources;

const {
[apiGatewayDeploymentPropertyKey]: apiGatewayDeployment,
[hello1LambdaVersionPropertyKey]: hello1LambdaVersion,
[hello2LambdaVersionPropertyKey]: hello2LambdaVersion,
...deterministicResources
} = cloudformation.Resources;

expect(deterministicResources).toMatchSnapshot({
Hello1LambdaFunction: {
Expand All @@ -48,13 +58,13 @@ test('individually', () => {
Code: { S3Key: expect.stringContaining('hello2.zip') },
},
},
[Object.keys(deterministicResources).find((s) => s.startsWith('Hello1LambdaVersion')) as string]: {
Properties: { CodeSha256: expect.any(String) },
},
[Object.keys(deterministicResources).find((s) => s.startsWith('Hello2LambdaVersion')) as string]: {
Properties: { CodeSha256: expect.any(String) },
},
});

expect(apiGatewayDeployment).toMatchSnapshot();
expect(hello1LambdaVersion).toMatchSnapshot({
Properties: { CodeSha256: expect.any(String) },
});
expect(hello2LambdaVersion).toMatchSnapshot({
Properties: { CodeSha256: expect.any(String) },
});
});
16 changes: 11 additions & 5 deletions e2e/minimal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@ test('minimal', () => {
s.startsWith('ApiGatewayDeployment')
) as keyof typeof cloudformation.Resources;

const { [apiGatewayDeploymentPropertyKey]: apiGatewayDeployment, ...deterministicResources } =
cloudformation.Resources;
const validateIsinLambdaVersionPropertyKey = cloudformation.Outputs.ValidateIsinLambdaFunctionQualifiedArn.Value
.Ref as keyof typeof cloudformation.Resources;

const {
[apiGatewayDeploymentPropertyKey]: apiGatewayDeployment,
[validateIsinLambdaVersionPropertyKey]: validateIsinLambdaVersion,
...deterministicResources
} = cloudformation.Resources;

expect(deterministicResources).toMatchSnapshot({
ValidateIsinLambdaFunction: {
Properties: {
Code: { S3Key: expect.stringContaining('minimal-example.zip') },
},
},
[Object.keys(deterministicResources).find((s) => s.startsWith('ValidateIsinLambdaVersion')) as string]: {
Properties: { CodeSha256: expect.any(String) },
},
});

expect(apiGatewayDeployment).toMatchSnapshot();
expect(validateIsinLambdaVersion).toMatchSnapshot({
Properties: { CodeSha256: expect.any(String) },
});
});

0 comments on commit 889524d

Please sign in to comment.