Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Amengual authored and Jose Amengual committed Jul 1, 2020
1 parent a0e09fb commit bbeae5c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@ import (

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
"math/rand"
"strconv"
"testing"
"time"
)

// Test the Terraform module in examples/complete using Terratest.
func TestExamplesComplete(t *testing.T) {
t.Parallel()

rand.Seed(time.Now().UnixNano())

attributes := []string{strconv.Itoa(rand.Intn(100000))}

// We need to create the ALB first because terraform does not wwait for it to be in the ready state before creating ECS target group
terraformOptions := &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: "../../examples/complete",
Upgrade: true,
// Variables to pass to our Terraform code using -var-file options
VarFiles: []string{"fixtures.us-east-2.tfvars"},
Vars: map[string]interface{}{
"attributes": attributes,
},
Targets: []string{"module.label", "module.vpc", "module.subnets", "module.alb"},
}

Expand Down Expand Up @@ -61,12 +72,14 @@ func TestExamplesComplete(t *testing.T) {
// Run `terraform output` to get the value of an output variable
albIngressTargetGroupName := terraform.Output(t, terraformOptions, "alb_ingress_target_group_name")
// Verify we're getting back the outputs we expect
assert.Equal(t, "eg-test-ecs-web-app", albIngressTargetGroupName)
expectedAlbIngressTargetGroupName := "eg-test-ecs-web-app-" + attributes[0]
assert.Equal(t, expectedAlbIngressTargetGroupName, albIngressTargetGroupName)

// Run `terraform output` to get the value of an output variable
albAccessLogsBucketId := terraform.Output(t, terraformOptions, "alb_access_logs_bucket_id")
// Verify we're getting back the outputs we expect
assert.Equal(t, "eg-test-ecs-web-app-alb-access-logs", albAccessLogsBucketId)
expectedAlbAccessLogsBucketId := "eg-test-ecs-web-app-alb-access-logs" + attributes[0]
assert.Equal(t, expectedAlbAccessLogsBucketId, albAccessLogsBucketId)

// Run `terraform output` to get the value of an output variable
containerDefinitionJsonMap := terraform.OutputRequired(t, terraformOptions, "container_definition_json_map")
Expand Down

0 comments on commit bbeae5c

Please sign in to comment.