Skip to content

Commit aa1ee1a

Browse files
krjakbrjakglours
authored andcommitted
fix extraction of variables
Signed-off-by: Nikita Vakula <[email protected]>
1 parent a42e757 commit aa1ee1a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

template/variables.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ func recurseExtract(value interface{}, pattern *regexp.Regexp) map[string]Variab
5757

5858
case []interface{}:
5959
for _, elem := range value {
60-
if values, is := extractVariable(elem, pattern); is {
61-
for _, v := range values {
62-
m[v.Name] = v
63-
}
60+
submap := recurseExtract(elem, pattern)
61+
for key, value := range submap {
62+
m[key] = value
6463
}
6564
}
6665
}

template/variables_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ func TestExtractVariables(t *testing.T) {
191191
"SUBDOMAIN": {Name: "SUBDOMAIN", DefaultValue: "$ROOTDOMAIN"},
192192
},
193193
},
194+
{
195+
name: "nested-array-of-maps",
196+
dict: map[string]interface{}{
197+
"volumes": []interface{}{
198+
map[string]interface{}{
199+
"source": "${SOURCE_LOCATION}",
200+
"target": "/location",
201+
"type": "volume",
202+
"volume": map[string]interface{}{},
203+
},
204+
},
205+
},
206+
expected: map[string]Variable{
207+
"SOURCE_LOCATION": {Name: "SOURCE_LOCATION"},
208+
},
209+
},
194210
}
195211
for _, tc := range testCases {
196212
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)