Skip to content

Commit

Permalink
(feat): Add iterator to child metadata
Browse files Browse the repository at this point in the history
Signed-off-by: florian.cazals <florian.cazals@ovhcloud.com>
  • Loading branch information
florian.cazals authored and rclsilver committed Feb 20, 2023
1 parent e630bb9 commit e2212aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,12 @@ func contractStep(s *step.Step, res *resolution.Resolution) {
if child.Metadata != nil {
childM[values.MetadataKey] = child.Metadata
}
childMMetadata := childM[values.MetadataKey].(map[string]interface{})
if childMMetadata == nil {
childMMetadata = make(map[string]interface{})
}
childMMetadata[values.IteratorKey] = child.Item
childM[values.MetadataKey] = childMMetadata
childM[values.StateKey] = child.State
var i interface{} = childM
collectedChildren = append(collectedChildren, i)
Expand Down
13 changes: 13 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,19 @@ func TestForeach(t *testing.T) {
firstItem := concatList[0].(map[string]interface{})
firstItemOutput := firstItem[values.OutputKey].(map[string]interface{})
assert.Equal(t, "foo-b-bar-b", firstItemOutput["concat"])

outputExpected := map[string]string{"foo": "foo-b", "bar": "bar-b"}
metadata, ok := firstItem[values.MetadataKey].(map[string]interface{})
require.True(t, ok)
iterator, ok := metadata[values.IteratorKey].(map[string]interface{})
require.True(t, ok)
outputInterface, ok := iterator["output"].(map[string]interface{})
require.True(t, ok)
output := make(map[string]string)
for key, value := range outputInterface {
output[key] = fmt.Sprintf("%v", value)
}
assert.Equal(t, outputExpected, output)
}

func TestForeachWithChainedIterations(t *testing.T) {
Expand Down

0 comments on commit e2212aa

Please sign in to comment.