Skip to content

Commit

Permalink
update other tests, add enabled: false test
Browse files Browse the repository at this point in the history
  • Loading branch information
Benbentwo committed Jul 22, 2024
1 parent e46a001 commit edb5c3d
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 34 deletions.
23 changes: 19 additions & 4 deletions test/src/examples_advanced_features.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"strings"
"testing"
)


// Test the Terraform module in examples/advanced_features using Terratest.
func TestExamplesAdvancedFeatures(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/advanced_features"
varFiles := []string{"fixtures.tfvars"}

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

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

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

// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
Expand Down
22 changes: 19 additions & 3 deletions test/src/examples_alert_policy_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

// Test the Terraform module in examples/alert_policy using Terratest.
func TestExamplesAlertPolicy(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/alert_policy"
varFiles := []string{"fixtures.tfvars"}

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

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

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

// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
Expand Down
22 changes: 19 additions & 3 deletions test/src/examples_api_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

// Test the Terraform module in examples/api_integration using Terratest.
func TestExamplesApiIntegration(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/api_integration"
varFiles := []string{"fixtures.tfvars"}

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

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

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

// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
Expand Down
37 changes: 37 additions & 0 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test

import (
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -67,3 +68,39 @@ func TestExamplesComplete(t *testing.T) {
// Verify we're getting back the outputs we expect
assert.Equal(t, expectedTeamName, outputTeamName)
}

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

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

tempTestFolder := testStructure.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.
// Extract the "Resources:" section of the output to make the error message more readable.
re := regexp.MustCompile(`Resources: [^.]+\.`)
match := re.FindString(results)
assert.Equal(t, "Resources: 0 added, 0 changed, 0 destroyed.", match, "Re-applying the same configuration should not change any resources")
}
22 changes: 19 additions & 3 deletions test/src/examples_config_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"strings"
"testing"
)

// Test the Terraform module in examples/config using Terratest.
func TestExamplesConfig(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/config"
varFiles := []string{"fixtures.tfvars"}

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

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

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

// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
Expand Down
22 changes: 19 additions & 3 deletions test/src/examples_escalation_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

// Test the Terraform module in examples/escalation using Terratest.
func TestExamplesEscalation(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/escalation"
varFiles := []string{"fixtures.tfvars"}

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

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

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

// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
Expand Down
25 changes: 20 additions & 5 deletions test/src/examples_integration_action.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"strings"
"testing"
)


// Test the Terraform module in examples/integration_action using Terratest.
func TestExamplesIntegrationAction(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/integration_action"
varFiles := []string{"fixtures.tfvars"}

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

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

// At the end of the test, run `terraform destroy` to clean up any resources that were created
defer terraform.Destroy(t, terraformOptions)
// 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
terraform.InitAndApply(t, terraformOptions)
Expand Down
22 changes: 19 additions & 3 deletions test/src/examples_notification_policy_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

// Test the Terraform module in examples/notification_policy using Terratest.
func TestExamplesNotificationPolicy(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/notification_policy"
varFiles := []string{"fixtures.tfvars"}

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

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

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

// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
Expand Down
22 changes: 19 additions & 3 deletions test/src/examples_team_routing_rule_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
package test

import (
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

// Test the Terraform module in examples/team_routing_rule using Terratest.
func TestExamplesTeamRoutingRule(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/team_routing_rule"
varFiles := []string{"fixtures.tfvars"}

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

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

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

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

0 comments on commit edb5c3d

Please sign in to comment.