Skip to content

Commit

Permalink
refactor test logic to compare index
Browse files Browse the repository at this point in the history
  • Loading branch information
chilledornaments committed Dec 18, 2022
1 parent 7da6e5e commit cee5e91
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions modules/terraform/format_test.go
Expand Up @@ -295,9 +295,20 @@ func TestFormatSetVarsAfterVarFilesFormatsCorrectly(t *testing.T) {
{[]string{"plan"}, map[string]interface{}{"foo": "bar"}, []string{"test.tfvars"}, false, []string{"plan", "-var", "foo=bar", "-var-file", "test.tfvars", "-lock=false"}},
}

for idx, testCase := range testCases {
checkResultWithRetry(t, 100, testCase.expected, fmt.Sprintf("FormatArgs(%d)", idx), func() interface{} {
return FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...)
})
for _, testCase := range testCases {
result := FormatArgs(&Options{SetVarsAfterVarFiles: testCase.setVarsAfterVarFiles, Vars: testCase.vars, VarFiles: testCase.varFiles}, testCase.command...)

// Make sure that -var and -var-file options are in the expected order relative to each other
// Note that the order of the different -var and -var-file options may change
// See this comment for more info: https://github.com/gruntwork-io/terratest/blob/6fb86056797e3e62ebdd9011ba26605e0976a6f8/modules/terraform/format_test.go#L123-L142
for idx, arg := range result {
if arg == "-var-file" || arg == "-var" {
assert.Equal(t, testCase.expected[idx], arg)
}
}

// Make sure that the order of other arguments hasn't been incorrectly modified
assert.Equal(t, testCase.expected[0], result[0])
assert.Equal(t, testCase.expected[len(testCase.expected)-1], result[len(result)-1])
}
}

0 comments on commit cee5e91

Please sign in to comment.