diff --git a/src/constructs/network.ts b/src/constructs/network.ts index 25cb01a..6192736 100644 --- a/src/constructs/network.ts +++ b/src/constructs/network.ts @@ -131,7 +131,7 @@ export class Network extends Construct { pb.addDefaultInternetRoute(internetGateway.ref, att); }); if (this.natSubnets.length > 0) { - if (props.natEipAllocationIds?.length != 0 && this.natSubnets.length != props.natEipAllocationIds?.length) { + if (props.natEipAllocationIds && this.natSubnets.length != props.natEipAllocationIds?.length) { // eslint-disable-next-line max-len throw new Error( 'natEipAllocationIds and natSubnets length should be equal', diff --git a/test/hello.test.ts b/test/hello.test.ts index 6e4c6d8..44cdbf6 100644 --- a/test/hello.test.ts +++ b/test/hello.test.ts @@ -1,5 +1,126 @@ -describe('my suite', () => { - test.only('my only true test', () => { - expect(1 + 1).toEqual(2); +import * as cdk from 'aws-cdk-lib'; +import * as ec2 from 'aws-cdk-lib/aws-ec2'; +import * as mod from '../src/index'; + +describe('Test', () => { + test('undefined natEip', () => { + + const app = new cdk.App(); + const test = new cdk.Stack(app, 'TestStack'); + + new mod.Network(test, 'NETWORK', { + vpc: { + cidr: '10.145.0.0/16', + subnetConfiguration: [], + }, + subnets: [ + { + subnetGroupName: 'NATGateway', + subnetType: ec2.SubnetType.PUBLIC, + cidrBlock: ['10.145.0.0/28', '10.145.0.16/28', '10.145.0.32/28'], + availabilityZones: ['ap-south-1a', 'ap-south-1b', 'ap-south-1c'], + ingressNetworkACL: [ + { + cidr: ec2.AclCidr.ipv4('0.0.0.0/0'), + traffic: ec2.AclTraffic.allTraffic(), + }, + ], + routes: [ + ], + egressNetworkACL: [ + { + cidr: ec2.AclCidr.ipv4('0.0.0.0/0'), + traffic: ec2.AclTraffic.allTraffic(), + }, + ], + }, + { + subnetGroupName: 'Private', + subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS, + cidrBlock: ['10.145.1.0/24', '10.145.2.0/24', '10.145.3.0/24'], + availabilityZones: ['ap-south-1a', 'ap-south-1b', 'ap-south-1c'], + ingressNetworkACL: [ + { + cidr: ec2.AclCidr.ipv4('0.0.0.0/0'), + traffic: ec2.AclTraffic.allTraffic(), + }, + ], + routes: [ + ], + egressNetworkACL: [ + { + cidr: ec2.AclCidr.ipv4('0.0.0.0/0'), + traffic: ec2.AclTraffic.allTraffic(), + }, + ], + tags: { + 'kubernetes.io/role/internal-elb': '1', + 'kubernetes.io/cluster/SC-PROD-APP': 'owned', + }, + }, + ], + }); }); -}); \ No newline at end of file + + + test('defined but emtpy natEip', () => { + const app = new cdk.App(); + const test = new cdk.Stack(app, 'TestStack2'); + + new mod.Network(test, 'NETWORK', { + vpc: { + cidr: '10.145.0.0/16', + subnetConfiguration: [], + }, + subnets: [ + { + subnetGroupName: 'NATGateway', + subnetType: ec2.SubnetType.PUBLIC, + cidrBlock: ['10.145.0.0/28', '10.145.0.16/28', '10.145.0.32/28'], + availabilityZones: ['ap-south-1a', 'ap-south-1b', 'ap-south-1c'], + ingressNetworkACL: [ + { + cidr: ec2.AclCidr.ipv4('0.0.0.0/0'), + traffic: ec2.AclTraffic.allTraffic(), + }, + ], + routes: [ + ], + egressNetworkACL: [ + { + cidr: ec2.AclCidr.ipv4('0.0.0.0/0'), + traffic: ec2.AclTraffic.allTraffic(), + }, + ], + }, + { + subnetGroupName: 'Private', + subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS, + cidrBlock: ['10.145.1.0/24', '10.145.2.0/24', '10.145.3.0/24'], + availabilityZones: ['ap-south-1a', 'ap-south-1b', 'ap-south-1c'], + ingressNetworkACL: [ + { + cidr: ec2.AclCidr.ipv4('0.0.0.0/0'), + traffic: ec2.AclTraffic.allTraffic(), + }, + ], + routes: [ + ], + egressNetworkACL: [ + { + cidr: ec2.AclCidr.ipv4('0.0.0.0/0'), + traffic: ec2.AclTraffic.allTraffic(), + }, + ], + tags: { + 'kubernetes.io/role/internal-elb': '1', + 'kubernetes.io/cluster/SC-PROD-APP': 'owned', + }, + }, + ], + }); + + expect(test).toThrowError; + }); +}); +