|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/gruntwork-io/terratest/modules/terraform" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +// Test the Terraform module in examples/complete using Terratest. |
| 11 | +func TestExamplesComplete(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + |
| 14 | + terraformOptions := &terraform.Options{ |
| 15 | + // The path to where our Terraform code is located |
| 16 | + TerraformDir: "../../examples/complete", |
| 17 | + } |
| 18 | + |
| 19 | + // At the end of the test, run `terraform destroy` to clean up any resources that were created |
| 20 | + defer terraform.Destroy(t, terraformOptions) |
| 21 | + |
| 22 | + // This will run `terraform init` and `terraform apply` and fail the test if there are any errors |
| 23 | + terraform.InitAndApply(t, terraformOptions) |
| 24 | + |
| 25 | + // Run `terraform output` to get the value of an output variable |
| 26 | + label1 := terraform.OutputMap(t, terraformOptions, "label1") |
| 27 | + |
| 28 | + // Verify we're getting back the outputs we expect |
| 29 | + assert.Equal(t, "winstonchurchroom-uat-build-fire-water-earth-air", label1["id"]) |
| 30 | + |
| 31 | + // Run `terraform output` to get the value of an output variable |
| 32 | + label2 := terraform.OutputMap(t, terraformOptions, "label2") |
| 33 | + |
| 34 | + // Verify we're getting back the outputs we expect |
| 35 | + assert.Equal(t, "charlie+uat+test+fire+water+earth+air", label2["id"]) |
| 36 | + |
| 37 | + // Run `terraform output` to get the value of an output variable |
| 38 | + label3 := terraform.OutputMap(t, terraformOptions, "label3") |
| 39 | + |
| 40 | + // Verify we're getting back the outputs we expect |
| 41 | + assert.Equal(t, "starfish.uat.release.fire.water.earth.air", label3["id"]) |
| 42 | +} |
0 commit comments