From d84e3a8c18f45c523f81a30dc29e4905ed7fb5d0 Mon Sep 17 00:00:00 2001 From: Nuru Date: Fri, 29 Apr 2022 14:56:56 -0700 Subject: [PATCH] Fix broken & disabled tests (#105) --- examples/vpc-endpoints/main.tf | 2 +- test/src/examples_complete_test.go | 33 +++++++++++++++++++++++++ test/src/examples_vpc_endpoints_test.go | 3 ++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/examples/vpc-endpoints/main.tf b/examples/vpc-endpoints/main.tf index 89ac501..a8ab76f 100644 --- a/examples/vpc-endpoints/main.tf +++ b/examples/vpc-endpoints/main.tf @@ -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 diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index c66fa14..0ab5404 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -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.") +} diff --git a/test/src/examples_vpc_endpoints_test.go b/test/src/examples_vpc_endpoints_test.go index a497094..4486713 100644 --- a/test/src/examples_vpc_endpoints_test.go +++ b/test/src/examples_vpc_endpoints_test.go @@ -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}