Skip to content

Commit

Permalink
Add another integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
t0yv0 committed Jul 31, 2024
1 parent 4f6582c commit 6367748
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
62 changes: 62 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,68 @@ func TestVpcIpamIpv4AutoCidrBlock(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestVpcIpamIpv4AutoCidrBlockWithSpecs(t *testing.T) {
dir := filepath.Join(getCwd(t), "vpc", "nodejs", "vpc-ipam-ipv4-auto-cidrblock-with-specs")
test := getNodeJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: dir,
RetryFailedSteps: true,
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
regionName := stack.Outputs["regionName"].(string)

assert.Equal(t, []interface{}{
map[string]interface{}{
"cidrMask": float64(25),
"size": float64(128),
"name": "private",
"type": "Private",
},
map[string]interface{}{
"cidrMask": float64(27),
"size": float64(32),
"name": "public",
"type": "Public",
},
}, stack.Outputs["subnetLayout"])

expectedSubnets := []interface{}{
map[string]interface{}{
"availabilityZone": fmt.Sprintf("%sa", regionName),
"cidrBlock": "172.20.0.128/27",
},
map[string]interface{}{
"availabilityZone": fmt.Sprintf("%sa", regionName),
"cidrBlock": "172.20.0.0/25",
},
map[string]interface{}{
"availabilityZone": fmt.Sprintf("%sb", regionName),
"cidrBlock": "172.20.1.128/27",
},
map[string]interface{}{
"availabilityZone": fmt.Sprintf("%sb", regionName),
"cidrBlock": "172.20.1.0/25",
},
map[string]interface{}{
"availabilityZone": fmt.Sprintf("%sc", regionName),
"cidrBlock": "172.20.2.128/27",
},
map[string]interface{}{
"availabilityZone": fmt.Sprintf("%sc", regionName),
"cidrBlock": "172.20.2.0/25",
},
}

actualSubnets := stack.Outputs["subnets"].([]any)
assert.Equal(t, len(expectedSubnets), len(actualSubnets))
for _, expsub := range expectedSubnets {
assert.Contains(t, actualSubnets, expsub)
}
},
})
integration.ProgramTest(t, &test)
}

func TestVpc(t *testing.T) {
test := getNodeJSBaseOptions(t).
With(integration.ProgramTestOptions{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/node_modules/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: vpc-ipam-ipv4-auto-cidrblock-with-specs
runtime:
name: nodejs
description: Test inheriting the cidrBlock from an IPv4 IPAM pool and constraining the subnet specs
config:
pulumi:tags:
value:
pulumi:template: aws-typescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as awsx from "@pulumi/awsx";
import * as aws from "@pulumi/aws";
import { SubnetAllocationStrategy } from "@pulumi/awsx/ec2";

const repository = "pulumi/pulumi-awsx";
const testcase = "vpc-ipam-ipv4-auto-cidrblock-with-specs";

const tags = {
"repository": repository,
"testcase": testcase,
};

const currentRegion = aws.getRegionOutput({});

const myVpcIpam = new aws.ec2.VpcIpam("myVpcIpam", {
operatingRegions: [{
regionName: currentRegion.name,
}],
description: `IPAM for ${repository} example ${testcase}`,
tags: tags,
});

const myVpcIpamPool = new aws.ec2.VpcIpamPool("myVpcIpamPool", {
addressFamily: "ipv4",
ipamScopeId: myVpcIpam.privateDefaultScopeId,
locale: currentRegion.name,
tags: tags,
});

const myVpcIpamPoolCidr = new aws.ec2.VpcIpamPoolCidr("myVpcIpamPoolCidr", {
ipamPoolId: myVpcIpamPool.id,
cidr: "172.20.0.0/16",
});

const myVpc = new awsx.ec2.Vpc("myVpc", {
numberOfAvailabilityZones: 3,
subnetStrategy: SubnetAllocationStrategy.Auto,
ipv4IpamPoolId: myVpcIpamPool.id,
ipv4NetmaskLength: 22,
subnetSpecs: [
{
type: "Private",
name: "private",
cidrMask: 25,
},
{
type: "Public",
name: "public",
cidrMask: 27,
},
],
tags: tags,
}, {
dependsOn: [myVpcIpamPoolCidr],
});

export const regionName = currentRegion.name;
export const subnetLayout = myVpc.subnetLayout;
export const subnets = myVpc.subnets.apply(s => s.map(x => ({
availabilityZone: x.availabilityZone,
cidrBlock: x.cidrBlock
})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "vpc-ipam-ipv4-auto-cidrblock-with-specs",
"main": "index.ts",
"devDependencies": {
"@types/node": "^18",
"typescript": "^5.0.0"
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/awsx": "^2.0.2",
"@pulumi/pulumi": "^3.113.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.ts"
]
}

0 comments on commit 6367748

Please sign in to comment.