Skip to content

Commit

Permalink
Fix tests (#42)
Browse files Browse the repository at this point in the history
* fix tests

* fix tests
  • Loading branch information
osterman authored Jun 13, 2020
1 parent 76ebd4a commit 84acd82
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ 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
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,
},
}

// At the end of the test, run `terraform destroy` to clean up any resources that were created
Expand All @@ -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])
}

0 comments on commit 84acd82

Please sign in to comment.