Skip to content

Commit

Permalink
fix: natEip should be undefined (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aatman authored May 4, 2023
1 parent a2ca736 commit 47f84a9
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/constructs/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
129 changes: 125 additions & 4 deletions test/hello.test.ts
Original file line number Diff line number Diff line change
@@ -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',
},
},
],
});
});
});


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;
});
});

0 comments on commit 47f84a9

Please sign in to comment.