Skip to content

Commit

Permalink
disable snapshot for inline lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrconley committed Sep 16, 2024
1 parent ef9b31f commit d8a7549
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AccessTracker } from "../mappings/access-tracker.js";
export function synthesizeConstructAndTestStability<T extends Construct, C extends Class<T>>(
constructClass: C,
props: ConstructorParameters<C>[2],
disableSnapshot = false,
) {
class TestClass extends AwsTerraformAdaptorStack {
public readonly resource: T = new constructClass(this, "resource", props);
Expand All @@ -33,7 +34,7 @@ export function synthesizeConstructAndTestStability<T extends Construct, C exten
});
testStack.prepareStack();
const synthStack = Testing.synth(testStack);
expect(synthStack).toMatchSnapshot();
if (!disableSnapshot) expect(synthStack).toMatchSnapshot();

return {
resource: testStack.resource,
Expand Down Expand Up @@ -67,6 +68,7 @@ export function synthesizeElementAndTestStability<
terraformClass: TC,
terraformProps: Omit<DeepRequiredProperties<ConstructorParameters<TC>[2]>, BaseTfResourceProps>,
unsupportedCfPropPaths: string[] = [],
disableSnapshot = false,
) {
class ConstructWrapper extends Construct {
public readonly resource: C;
Expand Down Expand Up @@ -94,7 +96,7 @@ export function synthesizeElementAndTestStability<
// Attempt to create a new instance of the construct with the unsupported properties
// This should throw an error if the properties are not removed
try {
synthesizeConstructAndTestStability(ConstructWrapper, props);
synthesizeConstructAndTestStability(ConstructWrapper, props, disableSnapshot);
throw new Error(
`Expected an error when creating an instance of ${constructClass.name} with unsupported properties: ${unsupportedProps}`,
);
Expand All @@ -111,7 +113,7 @@ export function synthesizeElementAndTestStability<
const propProxy = new AccessTracker(props);
unsupportedCfPropPaths.forEach(path => propProxy.removePropertiesUnderPath(path));

const output = synthesizeConstructAndTestStability(ConstructWrapper, propProxy.clone());
const output = synthesizeConstructAndTestStability(ConstructWrapper, propProxy.clone(), disableSnapshot);
const transformedResource = output.resource.node.tryFindChild("resource") as T;
expectResourcePropertiesMatch(transformedResource, terraformClass, terraformProps);

Expand Down Expand Up @@ -150,6 +152,7 @@ export function itShouldMapCfnElementToTerraformResource<
terraformClass: TC,
terraformProps: Omit<DeepRequiredProperties<ConstructorParameters<TC>[2]>, BaseTfResourceProps>,
unsupportedCfPropPaths: string[] = [],
disableSnapshot = false,
) {
it(`Should map ${(constructClass as unknown as { CFN_RESOURCE_TYPE_NAME: string }).CFN_RESOURCE_TYPE_NAME}`, () => {
synthesizeElementAndTestStability(
Expand All @@ -158,6 +161,7 @@ export function itShouldMapCfnElementToTerraformResource<
terraformClass,
terraformProps,
unsupportedCfPropPaths,
disableSnapshot,
);
});
}
1 change: 1 addition & 0 deletions src/__tests__/mappings/lambda.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ describe("Lambda mappings", () => {
},
},
["runtimeManagementConfig", "recursiveLoop", "code.sourceKmsKeyArn"],
true,
);
});

Expand Down

0 comments on commit d8a7549

Please sign in to comment.