Skip to content

Commit

Permalink
fix(decl/loader): fix field bindings marshaling for nested fields
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Giovanna <[email protected]>
Co-authored-by: Aldo Lacuku <[email protected]>
  • Loading branch information
ekoops and alacuku committed Dec 6, 2024
1 parent 48e87dd commit 3f82db0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/test/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"reflect"
"regexp"
"strings"

"github.com/go-playground/validator/v10"
"github.com/go-viper/mapstructure/v2"
Expand Down Expand Up @@ -579,9 +580,23 @@ func (s TestStep) MarshalYAML() (any, error) {
for arg, argValue := range spec.Args {
args[arg] = argValue
}

// Restore field bindings in the original locations.
for _, fieldBinding := range s.FieldBindings {
args[fieldBinding.LocalField] = fmt.Sprintf("${%s.%s}", fieldBinding.SrcStep, fieldBinding.SrcField)
localFieldSegments := strings.Split(fieldBinding.LocalField, ".")
fieldContainer := args
for _, fieldSegment := range localFieldSegments[:len(localFieldSegments)-1] {
value, ok := fieldContainer[fieldSegment]
if !ok {
value = map[string]any{}
fieldContainer[fieldSegment] = value
}
fieldContainer = value.(map[string]any)
}
fieldContainer[localFieldSegments[len(localFieldSegments)-1]] = fmt.Sprintf("${%s.%s}",
fieldBinding.SrcStep, fieldBinding.SrcField)
}

return struct {
Type TestStepType `yaml:"type"`
Name string `yaml:"name"`
Expand Down

0 comments on commit 3f82db0

Please sign in to comment.