config: removeCurrent finds the proper map

This commit is contained in:
Mitchell Hashimoto 2014-10-09 17:23:10 -07:00
parent 3aa655ad3b
commit a931707a6a
2 changed files with 27 additions and 11 deletions

View File

@ -195,19 +195,24 @@ func (w *interpolationWalker) Primitive(v reflect.Value) error {
}
func (w *interpolationWalker) removeCurrent() {
c := w.cs[len(w.cs)-1]
switch c.Kind() {
case reflect.Map:
// Zero value so that we delete the map key
var val reflect.Value
// Get the key and delete it
k := w.csData.(reflect.Value)
c.SetMapIndex(k, val)
}
// Append the key to the unknown keys
w.unknownKeys = append(w.unknownKeys, strings.Join(w.key, "."))
for i := 1; i <= len(w.cs); i++ {
c := w.cs[len(w.cs)-i]
switch c.Kind() {
case reflect.Map:
// Zero value so that we delete the map key
var val reflect.Value
// Get the key and delete it
k := w.csData.(reflect.Value)
c.SetMapIndex(k, val)
return
}
}
panic("No container found for removeCurrent")
}
func (w *interpolationWalker) replaceCurrent(v reflect.Value) {

View File

@ -188,6 +188,17 @@ func TestInterpolationWalker_replace(t *testing.T) {
},
Value: "bar" + InterpSplitDelim + "baz",
},
{
Input: map[string]interface{}{
"foo": []interface{}{
"${var.foo}",
"bing",
},
},
Output: map[string]interface{}{},
Value: UnknownVariableValue + InterpSplitDelim + "baz",
},
}
for i, tc := range cases {