Skip to content

Commit 295c4f7

Browse files
authored
Merge pull request #28 from masterpointio/feat/testing
feat: native Terraform test framework
2 parents 2c85834 + fb67a07 commit 295c4f7

File tree

7 files changed

+60
-211
lines changed

7 files changed

+60
-211
lines changed

tests/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/Gopkg.lock

Lines changed: 0 additions & 100 deletions
This file was deleted.

tests/Gopkg.toml

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/Makefile

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
variables {
2-
vpc_id = "vpc-12345678"
3-
subnet_ids = ["subnet-12345678", "subnet-87654321"]
4-
stage = "test"
5-
namespace = "mp"
6-
name = "ssm-agent"
7-
region = "us-east-1"
8-
availability_zones = ["us-east-1a"]
2+
vpc_id = "vpc-12345678"
3+
subnet_ids = ["subnet-12345678", "subnet-87654321"]
4+
stage = "test"
5+
namespace = "mp"
6+
name = "ssm-agent"
7+
region = "us-east-1"
8+
availability_zones = ["us-east-1a"]
99
nat_gateway_enabled = true
10-
ipv6_enabled = true
10+
ipv6_enabled = true
1111
}
1212

1313
### TESTING INSTANCE and ARCHITECTURE COMPATIBILITY ###
@@ -20,7 +20,7 @@ run "valid_x86_64_instance" {
2020

2121
variables {
2222
instance_type = "t3.micro"
23-
architecture = "x86_64"
23+
architecture = "x86_64"
2424
}
2525

2626
assert {
@@ -35,7 +35,7 @@ run "valid_arm64_instance" {
3535

3636
variables {
3737
instance_type = "t4g.micro"
38-
architecture = "arm64"
38+
architecture = "arm64"
3939
}
4040

4141
assert {
@@ -50,7 +50,7 @@ run "invalid_x86_64_instance" {
5050

5151
variables {
5252
instance_type = "t4g.micro"
53-
architecture = "x86_64"
53+
architecture = "x86_64"
5454
}
5555

5656
expect_failures = [
@@ -64,7 +64,7 @@ run "invalid_arm64_instance" {
6464

6565
variables {
6666
instance_type = "t3.micro"
67-
architecture = "arm64"
67+
architecture = "arm64"
6868
}
6969

7070
expect_failures = [
@@ -79,7 +79,7 @@ run "graphics_instance_arm_incompatiblity_edge_case" {
7979

8080
variables {
8181
instance_type = "g3s.xlarge"
82-
architecture = "arm64"
82+
architecture = "arm64"
8383
}
8484

8585
expect_failures = [
@@ -94,7 +94,7 @@ run "graphics_instance_x86_compatibility_edge_case" {
9494

9595
variables {
9696
instance_type = "g4dn.xlarge"
97-
architecture = "x86_64"
97+
architecture = "x86_64"
9898
}
9999

100100
assert {

tests/examples_complete_test.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/unit.tftest.hcl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
variables {
2+
vpc_id = "vpc-12345678"
3+
subnet_ids = ["subnet-12345678", "subnet-87654321"]
4+
stage = "test"
5+
namespace = "mp"
6+
name = "ssm-agent"
7+
region = "us-east-1"
8+
availability_zones = ["us-east-1a"]
9+
nat_gateway_enabled = true
10+
ipv6_enabled = true
11+
}
12+
13+
run "verify_session_logging" {
14+
command = plan
15+
16+
variables {
17+
session_logging_enabled = true
18+
session_logging_bucket_name = ""
19+
session_logging_encryption_enabled = true
20+
cloudwatch_retention_in_days = 365
21+
}
22+
23+
assert {
24+
condition = aws_cloudwatch_log_group.session_logging[0].retention_in_days == 365
25+
error_message = "CloudWatch log retention days not set correctly when variables passed in."
26+
}
27+
28+
assert {
29+
condition = length(aws_iam_role_policy.session_logging) > 0
30+
error_message = "Session logging IAM policy not created when variables passed in."
31+
}
32+
}
33+
34+
run "verify_session_logging_bucket_logic" {
35+
command = plan
36+
37+
variables {
38+
session_logging_enabled = true
39+
session_logging_bucket_name = "" # Empty name should trigger bucket creation
40+
}
41+
42+
assert {
43+
condition = local.logs_bucket_enabled == true
44+
error_message = "Logs bucket should be enabled when session logging is enabled and no bucket name is provided"
45+
}
46+
}

0 commit comments

Comments
 (0)