forked from gruntwork-io/terraform-aws-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_remove_test.go
139 lines (129 loc) · 2.67 KB
/
list_remove_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package test
import (
"os"
"path/filepath"
"testing"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/terraform"
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
)
func TestListRemove(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
inputList []string
itemsToRemove []string
expectedOut string
}{
// Canonical use case: all elements in itemsToRemove exist in input
{
"canonical",
[]string{
"us-east-1a",
"us-east-1b",
"us-east-1c",
"us-east-1d",
"us-east-1e",
},
[]string{
"us-east-1b",
"us-east-1c",
},
"us-east-1a,us-east-1d,us-east-1e",
},
// Empty lists case
{
"both_empty",
[]string{},
[]string{},
"",
},
// Empty items to remove case
{
"empty_remove",
[]string{
"us-east-1a",
"us-east-1b",
"us-east-1c",
},
[]string{},
"us-east-1a,us-east-1b,us-east-1c",
},
// Empty input case
{
"empty_input",
[]string{},
[]string{
"us-east-1a",
"us-east-1b",
"us-east-1c",
},
"",
},
// No items in items to remove actually exist in input
{
"no_overlap",
[]string{
"us-east-1a",
"us-east-1b",
"us-east-1c",
},
[]string{
"us-east-1d",
"us-east-1e",
},
"us-east-1a,us-east-1b,us-east-1c",
},
// Removing duplicates
{
"remove_duplicates",
[]string{
"us-east-1a",
"us-east-1a",
"us-east-1a",
"us-east-1b",
"us-east-1c",
"us-east-1c",
},
[]string{
"us-east-1a",
"us-east-1c",
},
"us-east-1b",
},
// Remove all
{
"remove_all",
[]string{
"us-east-1a",
"us-east-1b",
"us-east-1c",
},
[]string{
"us-east-1a",
"us-east-1b",
"us-east-1c",
},
"",
},
}
for _, testCase := range testCases {
// Capture range variable to bring it in scope of this block, to avoid it being changed by for loop when test is
// run in parallel.
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
testFolder := test_structure.CopyTerraformFolderToTemp(t, "..", "examples")
defer os.RemoveAll(testFolder)
terraformModulePath := filepath.Join(testFolder, "list-remove")
logger.Logf(t, "Test folder is %s", terraformModulePath)
terratestOptions := createBaseTerratestOptions(t, terraformModulePath)
terratestOptions.Vars = map[string]interface{}{
"input_list": testCase.inputList,
"items_to_remove": testCase.itemsToRemove,
}
defer terraform.Destroy(t, terratestOptions)
terraform.InitAndApply(t, terratestOptions)
assertOutputEquals(t, "output_list_as_csv", testCase.expectedOut, terratestOptions)
})
}
}