|
1 |
| -import { UpdateFunctionCodeCommand, waitUntilFunctionUpdatedV2 } from '@aws-sdk/client-lambda'; |
2 |
| -import * as setup from './hotswap-test-setup'; |
3 |
| -import { HotswapMode } from '../../../lib/api/hotswap/common'; |
4 |
| -import { mockLambdaClient } from '../../util/mock-sdk'; |
5 |
| -import { silentTest } from '../../util/silent'; |
6 |
| - |
| 1 | +let mockWaitUntilFunctionUpdatedV2: jest.Mock = jest.fn(); |
7 | 2 | jest.mock('@aws-sdk/client-lambda', () => {
|
8 | 3 | const original = jest.requireActual('@aws-sdk/client-lambda');
|
9 | 4 |
|
10 | 5 | return {
|
11 | 6 | ...original,
|
12 |
| - waitUntilFunctionUpdatedV2: jest.fn(), |
| 7 | + waitUntilFunctionUpdatedV2: mockWaitUntilFunctionUpdatedV2, |
13 | 8 | };
|
14 | 9 | });
|
15 | 10 |
|
| 11 | +import { UpdateFunctionCodeCommand, waitUntilFunctionUpdatedV2 } from '@aws-sdk/client-lambda'; |
| 12 | +import * as setup from './hotswap-test-setup'; |
| 13 | +import { HotswapMode } from '../../../lib/api/hotswap/common'; |
| 14 | +import { mockLambdaClient } from '../../util/mock-sdk'; |
| 15 | +import { silentTest } from '../../util/silent'; |
| 16 | + |
16 | 17 | let hotswapMockSdkProvider: setup.HotswapMockSdkProvider;
|
17 | 18 |
|
18 | 19 | beforeEach(() => {
|
@@ -125,4 +126,61 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
|
125 | 126 | { FunctionName: 'my-function' },
|
126 | 127 | );
|
127 | 128 | });
|
| 129 | + |
| 130 | + silentTest( |
| 131 | + 'throws error in case of timeout', |
| 132 | + async () => { |
| 133 | + // GIVEN |
| 134 | + mockWaitUntilFunctionUpdatedV2.mockRejectedValue({ |
| 135 | + name: 'TimeoutError', |
| 136 | + message: JSON.stringify({ |
| 137 | + state: 'TIMEOUT', |
| 138 | + reason: 'Function not found', |
| 139 | + observedResponses: { |
| 140 | + '404: The function with name foo cannot be found.': 5, |
| 141 | + }, |
| 142 | + }), |
| 143 | + }); |
| 144 | + setup.setCurrentCfnStackTemplate({ |
| 145 | + Resources: { |
| 146 | + Func: { |
| 147 | + Type: 'AWS::Lambda::Function', |
| 148 | + Properties: { |
| 149 | + Code: { |
| 150 | + ImageUri: 'current-image', |
| 151 | + }, |
| 152 | + FunctionName: 'my-function', |
| 153 | + }, |
| 154 | + Metadata: { |
| 155 | + 'aws:asset:path': 'old-path', |
| 156 | + }, |
| 157 | + }, |
| 158 | + }, |
| 159 | + }); |
| 160 | + const cdkStackArtifact = setup.cdkStackArtifactOf({ |
| 161 | + template: { |
| 162 | + Resources: { |
| 163 | + Func: { |
| 164 | + Type: 'AWS::Lambda::Function', |
| 165 | + Properties: { |
| 166 | + Code: { |
| 167 | + ImageUri: 'new-image', |
| 168 | + }, |
| 169 | + FunctionName: 'my-function', |
| 170 | + }, |
| 171 | + Metadata: { |
| 172 | + 'aws:asset:path': 'new-path', |
| 173 | + }, |
| 174 | + }, |
| 175 | + }, |
| 176 | + }, |
| 177 | + }); |
| 178 | + |
| 179 | + // THEN |
| 180 | + await expect(hotswapMockSdkProvider.tryHotswapDeployment(hotswapMode, cdkStackArtifact)) |
| 181 | + .rejects |
| 182 | + .toThrow(`Resource is not in the expected state due to waiter status: TIMEOUT. Function not found. Observed responses: |
| 183 | + - 404: The function with name foo cannot be found. (5)`); |
| 184 | + }, |
| 185 | + ); |
128 | 186 | });
|
0 commit comments