Skip to content

Commit cee5e91

Browse files
refactor test logic to compare index
1 parent 7da6e5e commit cee5e91

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

modules/terraform/format_test.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,20 @@ func TestFormatSetVarsAfterVarFilesFormatsCorrectly(t *testing.T) {
295295
{[]string{"plan"}, map[string]interface{}{"foo": "bar"}, []string{"test.tfvars"}, false, []string{"plan", "-var", "foo=bar", "-var-file", "test.tfvars", "-lock=false"}},
296296
}
297297

298-
for idx, testCase := range testCases {
299-
checkResultWithRetry(t, 100, testCase.expected, fmt.Sprintf("FormatArgs(%d)", idx), func() interface{} {
300-
return FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...)
301-
})
298+
for _, testCase := range testCases {
299+
result := FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...)
300+
301+
// Make sure that -var and -var-file options are in the expected order relative to each other
302+
// Note that the order of the different -var and -var-file options may change
303+
// See this comment for more info: https://github.com/gruntwork-io/terratest/blob/6fb86056797e3e62ebdd9011ba26605e0976a6f8/modules/terraform/format_test.go#L123-L142
304+
for idx, arg := range result {
305+
if arg == "-var-file" || arg == "-var" {
306+
assert.Equal(t, testCase.expected[idx], arg)
307+
}
308+
}
309+
310+
// Make sure that the order of other arguments hasn't been incorrectly modified
311+
assert.Equal(t, testCase.expected[0], result[0])
312+
assert.Equal(t, testCase.expected[len(testCase.expected)-1], result[len(result)-1])
302313
}
303314
}

0 commit comments

Comments
 (0)