From 84acd82e682df03215943f8a7cf58fdfc02110c4 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Sat, 13 Jun 2020 13:39:39 -0700 Subject: [PATCH] Fix tests (#42) * fix tests * fix tests --- test/src/examples_complete_test.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index adb21c6..d3a0316 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -5,11 +5,17 @@ import ( "github.com/gruntwork-io/terratest/modules/terraform" "github.com/stretchr/testify/assert" + "math/rand" + "strconv" + "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))} terraformOptions := &terraform.Options{ // The path to where our Terraform code is located @@ -17,6 +23,9 @@ func TestExamplesComplete(t *testing.T) { 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, + }, } // At the end of the test, run `terraform destroy` to clean up any resources that were created @@ -42,21 +51,21 @@ func TestExamplesComplete(t *testing.T) { // Run `terraform output` to get the value of an output variable accessLogsBucketId := terraform.Output(t, terraformOptions, "access_logs_bucket_id") - // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-alb-alb-access-logs", accessLogsBucketId) + // Verify we're getting back the outputs we expect eg-test-alb-25346-alb-access-logs + assert.Equal(t, "eg-test-alb-"+attributes[0]+"-alb-access-logs", accessLogsBucketId) // Run `terraform output` to get the value of an output variable albName := terraform.Output(t, terraformOptions, "alb_name") // Verify we're getting back the outputs we expect - assert.Equal(t, "eg-test-alb", albName) + assert.Equal(t, "eg-test-alb-"+attributes[0], albName) // Run `terraform output` to get the value of an output variable defaultTargetGroupArn := terraform.Output(t, terraformOptions, "default_target_group_arn") - // Verify we're getting back the outputs we expect - assert.Contains(t, defaultTargetGroupArn, "arn:aws:elasticloadbalancing:us-east-2:126450723953:targetgroup/eg-test-alb-default") + // Verify we're getting back the outputs we expect something like "arn:aws:elasticloadbalancing:us-east-2:126450723953:targetgroup/eg-test-alb-11514-default/89e9fe401fc63cf7 + assert.Contains(t, defaultTargetGroupArn, "arn:aws:elasticloadbalancing:us-east-2:126450723953:targetgroup/eg-test-alb-"+attributes[0]+"-default") // Run `terraform output` to get the value of an output variable httpListenerArn := terraform.Output(t, terraformOptions, "http_listener_arn") // Verify we're getting back the outputs we expect - assert.Contains(t, httpListenerArn, "arn:aws:elasticloadbalancing:us-east-2:126450723953:listener/app/eg-test-alb") + assert.Contains(t, httpListenerArn, "arn:aws:elasticloadbalancing:us-east-2:126450723953:listener/app/eg-test-alb-"+attributes[0]) }