|
1 |
| -import { Match, Template } from '@aws-cdk/assertions'; |
| 1 | +import { Annotations, Match, Template } from '@aws-cdk/assertions'; |
2 | 2 | import * as ec2 from '@aws-cdk/aws-ec2';
|
3 | 3 | import * as ecs from '@aws-cdk/aws-ecs';
|
4 | 4 | import * as events from '@aws-cdk/aws-events';
|
@@ -410,3 +410,48 @@ test('Scheduled Fargate Task - exposes ECS Task', () => {
|
410 | 410 | // THEN
|
411 | 411 | expect(scheduledFargateTask.task).toBeDefined();
|
412 | 412 | });
|
| 413 | + |
| 414 | +test('Scheduled Fargate Task shows warning when minute is not defined in cron', () => { |
| 415 | + // GIVEN |
| 416 | + const stack = new cdk.Stack(); |
| 417 | + const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 1 }); |
| 418 | + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); |
| 419 | + |
| 420 | + new ScheduledFargateTask(stack, 'ScheduledFargateTask', { |
| 421 | + cluster, |
| 422 | + scheduledFargateTaskImageOptions: { |
| 423 | + image: ecs.ContainerImage.fromRegistry('henk'), |
| 424 | + memoryLimitMiB: 512, |
| 425 | + }, |
| 426 | + schedule: events.Schedule.cron({}), |
| 427 | + }); |
| 428 | + |
| 429 | + // THEN |
| 430 | + expect(stack.node.metadataEntry).toEqual([{ |
| 431 | + type: 'aws:cdk:warning', |
| 432 | + data: 'cron: If you don\'t pass \'minute\', by default the event runs every minute. Pass \'minute: \'*\'\' if that\'s what you intend, or \'minute: 0\' to run once per hour instead.', |
| 433 | + trace: undefined, |
| 434 | + }]); |
| 435 | + Annotations.fromStack(stack).hasWarning('/Default', "cron: If you don't pass 'minute', by default the event runs every minute. Pass 'minute: '*'' if that's what you intend, or 'minute: 0' to run once per hour instead."); |
| 436 | +}); |
| 437 | + |
| 438 | +test('Scheduled Fargate Task shows no warning when minute is * in cron', () => { |
| 439 | + // GIVEN |
| 440 | + const stack = new cdk.Stack(); |
| 441 | + const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 1 }); |
| 442 | + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); |
| 443 | + |
| 444 | + new ScheduledFargateTask(stack, 'ScheduledFargateTask', { |
| 445 | + cluster, |
| 446 | + scheduledFargateTaskImageOptions: { |
| 447 | + image: ecs.ContainerImage.fromRegistry('henk'), |
| 448 | + memoryLimitMiB: 512, |
| 449 | + }, |
| 450 | + schedule: events.Schedule.cron({ minute: '*' }), |
| 451 | + }); |
| 452 | + |
| 453 | + // THEN |
| 454 | + expect(stack.node.metadataEntry).toEqual([]); |
| 455 | + const annotations = Annotations.fromStack(stack).findWarning('*', Match.anyValue()); |
| 456 | + expect(annotations.length).toBe(0); |
| 457 | +}); |
0 commit comments