From 7222bf403933dd6de056d5687864bf5a4263115e Mon Sep 17 00:00:00 2001 From: Kailey Chen Date: Thu, 3 Oct 2024 15:41:57 -0700 Subject: [PATCH] additional test coverage --- .../@aws-cdk/aws-ec2-alpha/test/route.test.ts | 70 ++++++++++++------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/packages/@aws-cdk/aws-ec2-alpha/test/route.test.ts b/packages/@aws-cdk/aws-ec2-alpha/test/route.test.ts index d37a4c1acf561..cf229a9ead0c7 100644 --- a/packages/@aws-cdk/aws-ec2-alpha/test/route.test.ts +++ b/packages/@aws-cdk/aws-ec2-alpha/test/route.test.ts @@ -546,7 +546,36 @@ describe('EC2 Routing', () => { }); }); - test('CIDR block overlap should throw error', () => { + test('Default region handling for same account peering', () => { + const vpc1 = new vpc.VpcV2(stack, 'VPC1', { + primaryAddressBlock: vpc.IpAddresses.ipv4('10.1.0.0/16'), + }); + + const vpc2 = new vpc.VpcV2(stack, 'VPC2', { + primaryAddressBlock: vpc.IpAddresses.ipv4('10.2.0.0/16'), + }); + + new route.VPCPeeringConnection(stack, 'TestPeering', { + isCrossAccount: false, + requestorVpc: vpc1, + acceptorVpc: vpc2, + }); + + const template = Template.fromStack(stack); + template.hasResourceProperties('AWS::EC2::VPCPeeringConnection', { + VpcId: { + 'Fn::GetAtt': ['VPC17DE2CF87', 'VpcId'], + }, + PeerVpcId: { + 'Fn::GetAtt': ['VPC2C1F0E711', 'VpcId'], + }, + PeerRegion: { + Ref: 'AWS::Region', + }, + }); + }); + + test('Overlap with primary CIDR block should throw error', () => { const vpc1 = new vpc.VpcV2(stack, 'VPC1', { primaryAddressBlock: vpc.IpAddresses.ipv4('10.0.0.0/16'), }); @@ -564,7 +593,7 @@ describe('EC2 Routing', () => { }).toThrow(/CIDR block should not overlap with existing subnet blocks/); }); - test('CIDR block overlap with secondary CIDR block should throw error', () => { + test('Overlap with secondary CIDR block should throw error', () => { const vpc1 = new vpc.VpcV2(stack, 'VPC1', { primaryAddressBlock: vpc.IpAddresses.ipv4('10.0.0.0/16'), secondaryAddressBlocks: [vpc.IpAddresses.ipv4('10.1.0.0/16', { cidrBlockName: 'Temp Block' })], @@ -584,9 +613,9 @@ describe('EC2 Routing', () => { }).toThrow(/CIDR block should not overlap with existing subnet blocks/); }); - test('Non overlapping CIDR blocks should succeed', () => { + test('Overlap with primary and secondary CIDR block should throw error', () => { const vpc1 = new vpc.VpcV2(stack, 'VPC1', { - primaryAddressBlock: vpc.IpAddresses.ipv4('10.0.0.0/16'), + primaryAddressBlock: vpc.IpAddresses.ipv4('10.3.0.0/16'), secondaryAddressBlocks: [vpc.IpAddresses.ipv4('10.1.0.0/16', { cidrBlockName: 'Temp Block' })], }); @@ -601,36 +630,27 @@ describe('EC2 Routing', () => { requestorVpc: vpc1, acceptorVpc: vpc2, }); - }).not.toThrow(); + }).toThrow(/CIDR block should not overlap with existing subnet blocks/); }); - test('Default region handling for same account peering', () => { + test('Non overlapping CIDR blocks should succeed', () => { const vpc1 = new vpc.VpcV2(stack, 'VPC1', { - primaryAddressBlock: vpc.IpAddresses.ipv4('10.1.0.0/16'), + primaryAddressBlock: vpc.IpAddresses.ipv4('10.0.0.0/16'), + secondaryAddressBlocks: [vpc.IpAddresses.ipv4('10.1.0.0/16', { cidrBlockName: 'Temp Block' })], }); const vpc2 = new vpc.VpcV2(stack, 'VPC2', { primaryAddressBlock: vpc.IpAddresses.ipv4('10.2.0.0/16'), + secondaryAddressBlocks: [vpc.IpAddresses.ipv4('10.3.0.0/16', { cidrBlockName: 'Temp Block' })], }); - new route.VPCPeeringConnection(stack, 'TestPeering', { - isCrossAccount: false, - requestorVpc: vpc1, - acceptorVpc: vpc2, - }); - - const template = Template.fromStack(stack); - template.hasResourceProperties('AWS::EC2::VPCPeeringConnection', { - VpcId: { - 'Fn::GetAtt': ['VPC17DE2CF87', 'VpcId'], - }, - PeerVpcId: { - 'Fn::GetAtt': ['VPC2C1F0E711', 'VpcId'], - }, - PeerRegion: { - Ref: 'AWS::Region', // CDK resolves this as the stack region - }, - }); + expect(() => { + new route.VPCPeeringConnection(stack, 'TestPeering', { + isCrossAccount: false, + requestorVpc: vpc1, + acceptorVpc: vpc2, + }); + }).not.toThrow(); }); }); });