|
1 | 1 | import { Match, Template } from '@aws-cdk/assertions';
|
2 | 2 | import { Vpc } from '@aws-cdk/aws-ec2';
|
3 | 3 | import * as ecs from '@aws-cdk/aws-ecs';
|
| 4 | +import { ContainerImage } from '@aws-cdk/aws-ecs'; |
4 | 5 | import { CompositePrincipal, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
|
5 | 6 | import { Duration, Stack } from '@aws-cdk/core';
|
6 |
| -import { ApplicationMultipleTargetGroupsFargateService, NetworkMultipleTargetGroupsFargateService, ApplicationLoadBalancedFargateService } from '../../lib'; |
| 7 | +import { ApplicationLoadBalancedFargateService, ApplicationMultipleTargetGroupsFargateService, NetworkLoadBalancedFargateService, NetworkMultipleTargetGroupsFargateService } from '../../lib'; |
7 | 8 |
|
8 | 9 | describe('When Application Load Balancer', () => {
|
9 | 10 | test('test Fargate loadbalanced construct with default settings', () => {
|
@@ -661,4 +662,75 @@ describe('When Network Load Balancer', () => {
|
661 | 662 | });
|
662 | 663 | }).toThrow(/You must specify one of: taskDefinition or image/);
|
663 | 664 | });
|
| 665 | + |
| 666 | + test('test Fargate networkloadbalanced construct with custom Port', () => { |
| 667 | + // GIVEN |
| 668 | + const stack = new Stack(); |
| 669 | + const vpc = new Vpc(stack, 'VPC'); |
| 670 | + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); |
| 671 | + |
| 672 | + new NetworkLoadBalancedFargateService(stack, 'NLBService', { |
| 673 | + cluster: cluster, |
| 674 | + memoryLimitMiB: 1024, |
| 675 | + cpu: 512, |
| 676 | + taskImageOptions: { |
| 677 | + image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), |
| 678 | + containerPort: 81, |
| 679 | + }, |
| 680 | + listenerPort: 8181, |
| 681 | + }); |
| 682 | + |
| 683 | + Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { |
| 684 | + Port: 81, |
| 685 | + Protocol: 'TCP', |
| 686 | + TargetType: 'ip', |
| 687 | + VpcId: { |
| 688 | + Ref: 'VPCB9E5F0B4', |
| 689 | + }, |
| 690 | + }); |
| 691 | + }); |
| 692 | + |
| 693 | + test('test Fargate multinetworkloadbalanced construct with custom Port', () => { |
| 694 | + // GIVEN |
| 695 | + const stack = new Stack(); |
| 696 | + const vpc = new Vpc(stack, 'VPC'); |
| 697 | + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); |
| 698 | + |
| 699 | + new NetworkMultipleTargetGroupsFargateService(stack, 'Service', { |
| 700 | + cluster, |
| 701 | + taskImageOptions: { |
| 702 | + image: ecs.ContainerImage.fromRegistry('test'), |
| 703 | + }, |
| 704 | + }); |
| 705 | + |
| 706 | + |
| 707 | + new NetworkMultipleTargetGroupsFargateService(stack, 'NLBService', { |
| 708 | + cluster: cluster, |
| 709 | + memoryLimitMiB: 1024, |
| 710 | + cpu: 512, |
| 711 | + taskImageOptions: { |
| 712 | + image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), |
| 713 | + }, |
| 714 | + loadBalancers: [ |
| 715 | + { |
| 716 | + name: 'lb1', |
| 717 | + listeners: [ |
| 718 | + { name: 'listener1', port: 8181 }, |
| 719 | + ], |
| 720 | + }, |
| 721 | + ], |
| 722 | + targetGroups: [{ |
| 723 | + containerPort: 81, |
| 724 | + }], |
| 725 | + }); |
| 726 | + |
| 727 | + Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', { |
| 728 | + Port: 81, |
| 729 | + Protocol: 'TCP', |
| 730 | + TargetType: 'ip', |
| 731 | + VpcId: { |
| 732 | + Ref: 'VPCB9E5F0B4', |
| 733 | + }, |
| 734 | + }); |
| 735 | + }); |
664 | 736 | });
|
0 commit comments