Skip to content

Commit

Permalink
test: add Fn::ImportValue resolution test
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwright committed Sep 27, 2023
1 parent e2d14c9 commit 41baea5
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/aws-cdk/test/api/hotswap/hotswap-deployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,70 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
}
});

test('can correctly reference Fn::ImportValue in hotswappable changes', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Func: {
Type: 'AWS::Lambda::Function',
Properties: {
Code: {
S3Bucket: 'current-bucket',
S3Key: 'old-key',
},
FunctionName: 'aws-my-function',
},
Metadata: {
'aws:asset:path': 'new-path',
},
},
},
});
const cdkStackArtifact = setup.cdkStackArtifactOf({
template: {
Resources: {
Func: {
Type: 'AWS::Lambda::Function',
Properties: {
Code: {
S3Bucket: 'current-bucket',
S3Key: {
'Fn::ImportValue': 'test-import',
},
},
FunctionName: 'aws-my-function',
},
Metadata: {
'aws:asset:path': 'new-path',
},
},
},
},
});

const listExports = jest.fn().mockReturnValue({
Exports: [
{
ExportingStackId: 'test-exporting-stack-id',
Name: 'test-import',
Value: 'new-key',
},
],
});
hotswapMockSdkProvider.mockSdkProvider.stubCloudFormation({
listExports,
});

// WHEN
const deployStackResult = await hotswapMockSdkProvider.tryHotswapDeployment(hotswapMode, cdkStackArtifact);

// THEN
expect(deployStackResult).not.toBeUndefined();
expect(mockUpdateLambdaCode).toHaveBeenCalledWith({
FunctionName: 'aws-my-function',
S3Bucket: 'current-bucket',
S3Key: 'new-key',
});
});
});

0 comments on commit 41baea5

Please sign in to comment.