Skip to content

Commit

Permalink
Fix broken & disabled tests (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored Apr 29, 2022
1 parent f79a217 commit d84e3a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/vpc-endpoints/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module "vpc_endpoints" {

module "subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "0.39.8"
version = "0.40.1"

availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
Expand Down
33 changes: 33 additions & 0 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,36 @@ func TestExamplesComplete(t *testing.T) {
expectedPublicSubnetCidrs := []string{"172.16.96.0/19", "172.16.128.0/19"}
assert.Equal(t, expectedPublicSubnetCidrs, publicSubnetCidrs)
}

func TestExamplesCompleteDisabled(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/complete"
varFiles := []string{"fixtures.us-east-2.tfvars"}

tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)

terraformOptions := &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: tempTestFolder,
Upgrade: true,
// Variables to pass to our Terraform code using -var-file options
VarFiles: varFiles,
Vars: map[string]interface{}{
"attributes": attributes,
"enabled": "false",
},
}

// At the end of the test, run `terraform destroy` to clean up any resources that were created
defer cleanup(t, terraformOptions, tempTestFolder)

// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
results := terraform.InitAndApply(t, terraformOptions)

// Should complete successfully without creating or changing any resources
assert.Contains(t, results, "Resources: 0 added, 0 changed, 0 destroyed.")
}
3 changes: 2 additions & 1 deletion test/src/examples_vpc_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ type VpcEndpoint struct {
}

// Test the Terraform module in examples/vpc_endpoints using Terratest.
func disabledTestExamplesVPCEndpoints(t *testing.T) {
func TestExamplesVPCEndpoints(t *testing.T) {
// Be careful with t.Parallel() unless you are using test_structure.CopyTerraformFolderToTemp
// or else you risk parallel executions clobbering each other's state or
// not really running in parallel due to state locks. We can do it here
// because each test is in its own directory.
t.Parallel()

randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

Expand Down

0 comments on commit d84e3a8

Please sign in to comment.