Skip to content

Commit 14143c4

Browse files
committed
test: add unit test for network module
1 parent 80bd12e commit 14143c4

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

tests/vpc_unit_tests.tftest.hcl

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
run "cidr_block_match" {
2+
command = plan
3+
4+
variables {
5+
region = "ap-south-1"
6+
vpc_cidr_block = "10.0.0.0/16"
7+
8+
public_subnet_cidrs = ["10.0.1.0/24", "10.0.2.0/24"]
9+
private_subnet_cidrs = ["10.0.3.0/24", "10.0.4.0/24"]
10+
availability_zones = ["ap-south-1a", "ap-south-1b"]
11+
}
12+
13+
module {
14+
source = "./modules/network/"
15+
}
16+
17+
assert {
18+
condition = aws_vpc.main.cidr_block == var.vpc_cidr_block
19+
error_message = "VPC CIDR block mismatch after creation"
20+
}
21+
}
22+
23+
run "tags_match" {
24+
command = plan
25+
26+
variables {
27+
region = "ap-south-1"
28+
vpc_cidr_block = "10.0.0.0/16"
29+
public_subnet_cidrs = ["10.0.1.0/24", "10.0.2.0/24"]
30+
private_subnet_cidrs = ["10.0.3.0/24", "10.0.4.0/24"]
31+
availability_zones = ["ap-south-1a", "ap-south-1b"]
32+
expected_tag_value = "atlantis-ecs-vpc"
33+
}
34+
35+
module {
36+
source = "./modules/network/"
37+
}
38+
39+
assert {
40+
condition = aws_vpc.main.tags["Name"] == var.expected_tag_value
41+
error_message = "Tags mismatch after creation"
42+
}
43+
}
44+
45+
46+
run "public_1_subnet_cidr_match" {
47+
command = plan
48+
49+
variables {
50+
region = "ap-south-1"
51+
vpc_cidr_block = "10.0.0.0/16"
52+
public_subnet_cidrs = ["10.0.1.0/24", "10.0.2.0/24"]
53+
private_subnet_cidrs = ["10.0.3.0/24", "10.0.4.0/24"]
54+
availability_zones = ["ap-south-1a", "ap-south-1b"]
55+
}
56+
57+
module {
58+
source = "./modules/network/"
59+
}
60+
61+
assert {
62+
condition = aws_subnet.public_1.cidr_block == var.public_subnet_cidrs[0]
63+
error_message = "Public Subnet 1 CIDR block mismatch after creation"
64+
}
65+
}
66+
67+
run "public_2_subnet_cidr_match" {
68+
command = plan
69+
70+
variables {
71+
region = "ap-south-1"
72+
vpc_cidr_block = "10.0.0.0/16"
73+
public_subnet_cidrs = ["10.0.1.0/24", "10.0.2.0/24"]
74+
private_subnet_cidrs = ["10.0.3.0/24", "10.0.4.0/24"]
75+
availability_zones = ["ap-south-1a", "ap-south-1b"]
76+
}
77+
78+
module {
79+
source = "./modules/network/"
80+
}
81+
82+
assert {
83+
condition = aws_subnet.public_2.cidr_block == var.public_subnet_cidrs[1]
84+
error_message = "Public Subnet 2 CIDR block mismatch after creation"
85+
}
86+
}
87+
88+
run "private_1_subnet_cidr_match" {
89+
command = plan
90+
91+
variables {
92+
region = "ap-south-1"
93+
vpc_cidr_block = "10.0.0.0/16"
94+
public_subnet_cidrs = ["10.0.1.0/24", "10.0.2.0/24"]
95+
private_subnet_cidrs = ["10.0.3.0/24", "10.0.4.0/24"]
96+
availability_zones = ["ap-south-1a", "ap-south-1b"]
97+
}
98+
99+
module {
100+
source = "./modules/network/"
101+
}
102+
103+
assert {
104+
condition = aws_subnet.private_1.cidr_block == var.private_subnet_cidrs[0]
105+
error_message = "Private Subnet 1 CIDR block mismatch after creation"
106+
}
107+
}
108+
109+
run "private_2_subnet_cidr_match" {
110+
command = plan
111+
112+
variables {
113+
region = "ap-south-1"
114+
vpc_cidr_block = "10.0.0.0/16"
115+
public_subnet_cidrs = ["10.0.1.0/24", "10.0.2.0/24"]
116+
private_subnet_cidrs = ["10.0.3.0/24", "10.0.4.0/24"]
117+
availability_zones = ["ap-south-1a", "ap-south-1b"]
118+
}
119+
120+
module {
121+
source = "./modules/network/"
122+
}
123+
124+
assert {
125+
condition = aws_subnet.private_2.cidr_block == var.private_subnet_cidrs[1]
126+
error_message = "Private Subnet 2 CIDR block mismatch after creation"
127+
}
128+
}

0 commit comments

Comments
 (0)