|
1 | 1 | import { toCloudFormation } from './util';
|
2 | 2 | import { Annotations } from '../../assertions';
|
3 |
| -import { CustomResource, Duration, RemovalPolicy, Stack } from '../lib'; |
| 3 | +import { CfnParameter, CustomResource, Duration, RemovalPolicy, Stack } from '../lib'; |
4 | 4 |
|
5 | 5 | describe('custom resource', () => {
|
6 | 6 | test('simple case provider identified by service token', () => {
|
@@ -201,6 +201,61 @@ describe('custom resource', () => {
|
201 | 201 | });
|
202 | 202 | });
|
203 | 203 |
|
| 204 | + test('set serviceTimeout with token as seconds', () => { |
| 205 | + // GIVEN |
| 206 | + const stack = new Stack(); |
| 207 | + const durToken = new CfnParameter(stack, 'MyParameter', { |
| 208 | + type: 'Number', |
| 209 | + default: 60, |
| 210 | + }); |
| 211 | + |
| 212 | + // WHEN |
| 213 | + new CustomResource(stack, 'MyCustomResource', { |
| 214 | + serviceToken: 'MyServiceToken', |
| 215 | + serviceTimeout: Duration.seconds(durToken.valueAsNumber), |
| 216 | + }); |
| 217 | + |
| 218 | + // THEN |
| 219 | + expect(toCloudFormation(stack)).toEqual({ |
| 220 | + Parameters: { |
| 221 | + MyParameter: { |
| 222 | + Default: 60, |
| 223 | + Type: 'Number', |
| 224 | + }, |
| 225 | + }, |
| 226 | + Resources: { |
| 227 | + MyCustomResource: { |
| 228 | + Type: 'AWS::CloudFormation::CustomResource', |
| 229 | + Properties: { |
| 230 | + ServiceToken: 'MyServiceToken', |
| 231 | + ServiceTimeout: { |
| 232 | + Ref: 'MyParameter', |
| 233 | + }, |
| 234 | + }, |
| 235 | + UpdateReplacePolicy: 'Delete', |
| 236 | + DeletionPolicy: 'Delete', |
| 237 | + }, |
| 238 | + }, |
| 239 | + }); |
| 240 | + }); |
| 241 | + |
| 242 | + test('throws error when serviceTimeout is set with token as units other than seconds', () => { |
| 243 | + // GIVEN |
| 244 | + const stack = new Stack(); |
| 245 | + const durToken = new CfnParameter(stack, 'MyParameter', { |
| 246 | + type: 'Number', |
| 247 | + default: 60, |
| 248 | + }); |
| 249 | + |
| 250 | + // WHEN |
| 251 | + expect(() => { |
| 252 | + new CustomResource(stack, 'MyCustomResource', { |
| 253 | + serviceToken: 'MyServiceToken', |
| 254 | + serviceTimeout: Duration.minutes(durToken.valueAsNumber), |
| 255 | + }); |
| 256 | + }).toThrow('Duration must be specified as \'Duration.seconds()\' here since its value comes from a token and cannot be converted (got Duration.minutes)'); |
| 257 | + }); |
| 258 | + |
204 | 259 | test.each([0, 4000])('throw an error when serviceTimeout is set to %d seconds.', (invalidSeconds: number) => {
|
205 | 260 | // GIVEN
|
206 | 261 | const stack = new Stack();
|
|
0 commit comments