forked from gruntwork-io/terraform-aws-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pex_test.go
81 lines (61 loc) · 2.41 KB
/
pex_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package test
import (
"fmt"
"path/filepath"
"testing"
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/assert"
)
func TestRunPex(t *testing.T) {
t.Parallel()
testFolder := test_structure.CopyTerraformFolderToTemp(t, "..", "examples")
terratestOptions := createBaseTerratestOptions(t, filepath.Join(testFolder, "pex"))
defer terraform.Destroy(t, terratestOptions)
expectedFoo := random.UniqueId()
terratestOptions.Vars = map[string]interface{}{
"echo_string": expectedFoo,
}
output := terraform.InitAndApply(t, terratestOptions)
assertOutputEquals(t, "command_echo", expectedFoo, terratestOptions)
assert.Contains(t, output, fmt.Sprintf("Environment variable: %s", expectedFoo))
}
func TestRunPexTriggers(t *testing.T) {
t.Parallel()
testFolder := test_structure.CopyTerraformFolderToTemp(t, "..", "examples")
terratestOptions := createBaseTerratestOptions(t, filepath.Join(testFolder, "pex"))
expectedFoo := random.UniqueId()
defer terraform.Destroy(t, terratestOptions)
terratestOptions.Vars = map[string]interface{}{
"echo_string": expectedFoo,
"triggers": map[string]string{
"id": expectedFoo,
},
}
terraform.InitAndApply(t, terratestOptions)
assertOutputEquals(t, "command_echo", expectedFoo, terratestOptions)
// Assert that there is no diff
exitCode := terraform.PlanExitCode(t, terratestOptions)
assert.Equal(t, exitCode, 0)
// Now modify the trigger and verify the null_resource is recreated
terratestOptions.Vars["triggers"].(map[string]string)["id"] = random.UniqueId()
exitCode = terraform.PlanExitCode(t, terratestOptions)
assert.NotEqual(t, exitCode, 0)
}
func TestRunPexDisabled(t *testing.T) {
t.Parallel()
testFolder := test_structure.CopyTerraformFolderToTemp(t, "..", "examples")
terratestOptions := createBaseTerratestOptions(t, filepath.Join(testFolder, "pex"))
defer terraform.Destroy(t, terratestOptions)
expectedFoo := random.UniqueId()
terratestOptions.Vars = map[string]interface{}{
"echo_string": expectedFoo,
"enabled": false,
}
output := terraform.InitAndApply(t, terratestOptions)
assert.NotContains(t, output, fmt.Sprintf("Environment variable: %s", expectedFoo))
allOutputs := terraform.OutputAll(t, terratestOptions)
_, hasOutput := allOutputs["command_echo"]
assert.False(t, hasOutput)
}