Add test to ensure key/values interp order

Test that interpolated values are returned in the order of the sorted
keys.
This commit is contained in:
James Bardin 2016-06-29 14:16:12 -04:00
parent bc163cadaa
commit e78dc291af
1 changed files with 51 additions and 0 deletions

View File

@ -890,6 +890,57 @@ func TestInterpolateFuncKeys(t *testing.T) {
})
}
// Confirm that keys return in sorted order, and values return in the order of
// their sorted keys.
func TestInterpolateFuncKeyValOrder(t *testing.T) {
testFunction(t, testFunctionConfig{
Vars: map[string]ast.Variable{
"var.foo": ast.Variable{
Type: ast.TypeMap,
Value: map[string]ast.Variable{
"D": ast.Variable{
Value: "2",
Type: ast.TypeString,
},
"C": ast.Variable{
Value: "Y",
Type: ast.TypeString,
},
"A": ast.Variable{
Value: "X",
Type: ast.TypeString,
},
"10": ast.Variable{
Value: "Z",
Type: ast.TypeString,
},
"1": ast.Variable{
Value: "4",
Type: ast.TypeString,
},
"3": ast.Variable{
Value: "W",
Type: ast.TypeString,
},
},
},
},
Cases: []testFunctionCase{
{
`${keys(var.foo)}`,
[]interface{}{"1", "10", "3", "A", "C", "D"},
false,
},
{
`${values(var.foo)}`,
[]interface{}{"4", "Z", "W", "X", "Y", "2"},
false,
},
},
})
}
func TestInterpolateFuncValues(t *testing.T) {
testFunction(t, testFunctionConfig{
Vars: map[string]ast.Variable{