Skip to content

Commit

Permalink
end-to-end test to boost java coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Francis <colifran@amazon.com>
  • Loading branch information
colifran committed Mar 31, 2024
1 parent 692696e commit c7d4cca
Show file tree
Hide file tree
Showing 19 changed files with 1,230 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/end-to-end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ test_case!(ecs, "EcsStack", &["java", "golang"]);
test_case!(ec2, "Ec2Stack", &["java", "golang"]);
test_case!(efs, "EfsStack", &["java", "golang"]);
test_case!(ec2_encryption, "Ec2EncryptionStack", &["golang", "java"]);
test_case!(subnets, "SubnetsStack", &["golang"]);

// Add new test cases here

Expand Down
17 changes: 17 additions & 0 deletions tests/end-to-end/subnets/csharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//Auto-generated
using Amazon.CDK;
sealed class Program
{
public static void Main(string[] args)
{
var app = new App(new AppProps
{
DefaultStackSynthesizer = new DefaultStackSynthesizer(new DefaultStackSynthesizerProps
{
GenerateBootstrapVersionRule = false,
}),
});
new SubnetsStack.SubnetsStack(app, "Stack");
app.Synth();
}
}
65 changes: 65 additions & 0 deletions tests/end-to-end/subnets/csharp/Stack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;
using Constructs;
using System.Collections.Generic;

namespace SubnetsStack
{
public class SubnetsStackProps : StackProps
{
}

/// <summary>
/// Creates a VPC with public and private subnets.
/// </summary>
public class SubnetsStack : Stack
{
public SubnetsStack(Construct scope, string id, SubnetsStackProps props = null) : base(scope, id, props)
{

// Resources
var internetGateway = new CfnInternetGateway(this, "InternetGateway", new CfnInternetGatewayProps
{
});
var myVpc = new CfnVPC(this, "MyVPC", new CfnVPCProps
{
CidrBlock = "10.0.0.0/16",
EnableDnsSupport = true,
EnableDnsHostnames = true,
});
var attachGateway = new CfnVPCGatewayAttachment(this, "AttachGateway", new CfnVPCGatewayAttachmentProps
{
VpcId = myVpc.Ref,
InternetGatewayId = internetGateway.Ref,
});
var privateSubnet = new CfnSubnet(this, "PrivateSubnet", new CfnSubnetProps
{
VpcId = myVpc.Ref,
CidrBlock = "10.0.2.0/24",
AvailabilityZone = "us-east-1b",
});
var publicSubnet = new CfnSubnet(this, "PublicSubnet", new CfnSubnetProps
{
VpcId = myVpc.Ref,
CidrBlock = "10.0.1.0/24",
AvailabilityZone = "us-east-1a",
MapPublicIpOnLaunch = true,
});
var routeTable = new CfnRouteTable(this, "RouteTable", new CfnRouteTableProps
{
VpcId = myVpc.Ref,
});
var publicRoute = new CfnRoute(this, "PublicRoute", new CfnRouteProps
{
RouteTableId = routeTable.Ref,
DestinationCidrBlock = "0.0.0.0/0",
GatewayId = internetGateway.Ref,
});
var publicSubnetRouteTableAssociation = new CfnSubnetRouteTableAssociation(this, "PublicSubnetRouteTableAssociation", new CfnSubnetRouteTableAssociationProps
{
SubnetId = publicSubnet.Ref,
RouteTableId = routeTable.Ref,
});
}
}
}
107 changes: 107 additions & 0 deletions tests/end-to-end/subnets/csharp/Stack.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
diff --git a/./tests/end-to-end/subnets/template.json b/tests/end-to-end/subnets-csharp-working-dir/cdk.out/Stack.template.json
index 754079e..2d877e3 100644
--- a/./tests/end-to-end/subnets/template.json
+++ b/tests/end-to-end/subnets-csharp-working-dir/cdk.out/Stack.template.json
@@ -1,62 +1,77 @@
{
- "AWSTemplateFormatVersion": "2010-09-09",
- "Description": "Creates a VPC with public and private subnets.",
"Resources": {
+ "InternetGateway": {
+ "Type": "AWS::EC2::InternetGateway"
+ },
"MyVPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
- "EnableDnsSupport": true,
- "EnableDnsHostnames": true
+ "EnableDnsHostnames": true,
+ "EnableDnsSupport": true
}
},
- "InternetGateway": {
- "Type": "AWS::EC2::InternetGateway"
- },
- "PublicSubnet": {
- "Type": "AWS::EC2::Subnet",
+ "AttachGateway": {
+ "Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
- "VpcId": { "Ref": "MyVPC" },
- "CidrBlock": "10.0.1.0/24",
- "AvailabilityZone": "us-east-1a",
- "MapPublicIpOnLaunch": true
+ "InternetGatewayId": {
+ "Ref": "InternetGateway"
+ },
+ "VpcId": {
+ "Ref": "MyVPC"
+ }
}
},
"PrivateSubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
- "VpcId": { "Ref": "MyVPC" },
+ "AvailabilityZone": "us-east-1b",
"CidrBlock": "10.0.2.0/24",
- "AvailabilityZone": "us-east-1b"
+ "VpcId": {
+ "Ref": "MyVPC"
+ }
}
},
- "AttachGateway": {
- "Type": "AWS::EC2::VPCGatewayAttachment",
+ "PublicSubnet": {
+ "Type": "AWS::EC2::Subnet",
"Properties": {
- "VpcId": { "Ref": "MyVPC" },
- "InternetGatewayId": { "Ref": "InternetGateway" }
+ "AvailabilityZone": "us-east-1a",
+ "CidrBlock": "10.0.1.0/24",
+ "MapPublicIpOnLaunch": true,
+ "VpcId": {
+ "Ref": "MyVPC"
+ }
}
},
"RouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
- "VpcId": { "Ref": "MyVPC" }
+ "VpcId": {
+ "Ref": "MyVPC"
+ }
}
},
"PublicRoute": {
"Type": "AWS::EC2::Route",
- "DependsOn": "AttachGateway",
"Properties": {
- "RouteTableId": { "Ref": "RouteTable" },
"DestinationCidrBlock": "0.0.0.0/0",
- "GatewayId": { "Ref": "InternetGateway" }
+ "GatewayId": {
+ "Ref": "InternetGateway"
+ },
+ "RouteTableId": {
+ "Ref": "RouteTable"
+ }
}
},
"PublicSubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
- "SubnetId": { "Ref": "PublicSubnet" },
- "RouteTableId": { "Ref": "RouteTable" }
+ "RouteTableId": {
+ "Ref": "RouteTable"
+ },
+ "SubnetId": {
+ "Ref": "PublicSubnet"
+ }
}
}
}
78 changes: 78 additions & 0 deletions tests/end-to-end/subnets/csharp/Stack.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"Resources": {
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway"
},
"MyVPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsHostnames": true,
"EnableDnsSupport": true
}
},
"AttachGateway": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"InternetGatewayId": {
"Ref": "InternetGateway"
},
"VpcId": {
"Ref": "MyVPC"
}
}
},
"PrivateSubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": "us-east-1b",
"CidrBlock": "10.0.2.0/24",
"VpcId": {
"Ref": "MyVPC"
}
}
},
"PublicSubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": "us-east-1a",
"CidrBlock": "10.0.1.0/24",
"MapPublicIpOnLaunch": true,
"VpcId": {
"Ref": "MyVPC"
}
}
},
"RouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "MyVPC"
}
}
},
"PublicRoute": {
"Type": "AWS::EC2::Route",
"Properties": {
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
},
"RouteTableId": {
"Ref": "RouteTable"
}
}
},
"PublicSubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "RouteTable"
},
"SubnetId": {
"Ref": "PublicSubnet"
}
}
}
}
}
104 changes: 104 additions & 0 deletions tests/end-to-end/subnets/golang/stack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package main

import (
cdk "github.com/aws/aws-cdk-go/awscdk/v2"
ec2 "github.com/aws/aws-cdk-go/awscdk/v2/awsec2"
"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
)

type SubnetsStackProps struct {
cdk.StackProps
}

/// Creates a VPC with public and private subnets.
type SubnetsStack struct {
cdk.Stack
}

func NewSubnetsStack(scope constructs.Construct, id string, props *SubnetsStackProps) *SubnetsStack {
var sprops cdk.StackProps
if props != nil {
sprops = props.StackProps
}
stack := cdk.NewStack(scope, &id, &sprops)

internetGateway := ec2.NewCfnInternetGateway(
stack,
jsii.String("InternetGateway"),
&ec2.CfnInternetGatewayProps{
},
)

myVpc := ec2.NewCfnVPC(
stack,
jsii.String("MyVPC"),
&ec2.CfnVPCProps{
CidrBlock: jsii.String("10.0.0.0/16"),
EnableDnsSupport: jsii.Bool(true),
EnableDnsHostnames: jsii.Bool(true),
},
)

attachGateway := ec2.NewCfnVPCGatewayAttachment(
stack,
jsii.String("AttachGateway"),
&ec2.CfnVPCGatewayAttachmentProps{
VpcId: myVpc.Ref(),
InternetGatewayId: internetGateway.Ref(),
},
)

ec2.NewCfnSubnet(
stack,
jsii.String("PrivateSubnet"),
&ec2.CfnSubnetProps{
VpcId: myVpc.Ref(),
CidrBlock: jsii.String("10.0.2.0/24"),
AvailabilityZone: jsii.String("us-east-1b"),
},
)

publicSubnet := ec2.NewCfnSubnet(
stack,
jsii.String("PublicSubnet"),
&ec2.CfnSubnetProps{
VpcId: myVpc.Ref(),
CidrBlock: jsii.String("10.0.1.0/24"),
AvailabilityZone: jsii.String("us-east-1a"),
MapPublicIpOnLaunch: jsii.Bool(true),
},
)

routeTable := ec2.NewCfnRouteTable(
stack,
jsii.String("RouteTable"),
&ec2.CfnRouteTableProps{
VpcId: myVpc.Ref(),
},
)

ec2.NewCfnRoute(
stack,
jsii.String("PublicRoute"),
&ec2.CfnRouteProps{
RouteTableId: routeTable.Ref(),
DestinationCidrBlock: jsii.String("0.0.0.0/0"),
GatewayId: internetGateway.Ref(),
},
)

ec2.NewCfnSubnetRouteTableAssociation(
stack,
jsii.String("PublicSubnetRouteTableAssociation"),
&ec2.CfnSubnetRouteTableAssociationProps{
SubnetId: publicSubnet.Ref(),
RouteTableId: routeTable.Ref(),
},
)

return &SubnetsStack{
Stack: stack,
}
}

Loading

0 comments on commit c7d4cca

Please sign in to comment.