Skip to content

Commit

Permalink
Merge pull request #9324 from deads2k/template-key
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Jun 14, 2016
2 parents 2326e1e + b469465 commit ad1561e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions pkg/util/stringreplace/object.go
Expand Up @@ -43,9 +43,12 @@ func visitValue(v reflect.Value, visitor func(string) string) {

case reflect.Map:
vt := v.Type().Elem()
for _, k := range v.MapKeys() {
val := visitUnsettableValues(vt, v.MapIndex(k), visitor)
v.SetMapIndex(k, val)
for _, oldKey := range v.MapKeys() {
newKey := visitUnsettableValues(oldKey.Type(), oldKey, visitor)
oldValue := v.MapIndex(oldKey)
newValue := visitUnsettableValues(vt, oldValue, visitor)
v.SetMapIndex(oldKey, reflect.Value{})
v.SetMapIndex(newKey, newValue)
}

case reflect.String:
Expand Down
10 changes: 5 additions & 5 deletions pkg/util/stringreplace/object_test.go
Expand Up @@ -39,7 +39,7 @@ func TestVisitObjectStringsOnStruct(t *testing.T) {
},
{
MapInMap: map[string]map[string]string{
"foo": {"bar": "sample-test"},
"sample-foo": {"sample-bar": "sample-test"},
},
},
},
Expand All @@ -49,7 +49,7 @@ func TestVisitObjectStringsOnStruct(t *testing.T) {
},
{
{ArrayInMap: map[string][]interface{}{"key": {"foo", "bar"}}},
{ArrayInMap: map[string][]interface{}{"key": {"sample-foo", "sample-bar"}}},
{ArrayInMap: map[string][]interface{}{"sample-key": {"sample-foo", "sample-bar"}}},
},
}
for i := range samples {
Expand All @@ -69,15 +69,15 @@ func TestVisitObjectStringsOnMap(t *testing.T) {
samples := [][]map[string]string{
{
{"foo": "bar"},
{"foo": "sample-bar"},
{"sample-foo": "sample-bar"},
},
{
{"empty": ""},
{"empty": "sample-"},
{"sample-empty": "sample-"},
},
{
{"": "invalid"},
{"": "sample-invalid"},
{"sample-": "sample-invalid"},
},
}

Expand Down

0 comments on commit ad1561e

Please sign in to comment.