Skip to content

Commit

Permalink
incorporating review comments
Browse files Browse the repository at this point in the history
Signed-off-by: parth aranke <arankeparth1912@gmail.com>
  • Loading branch information
arankeparth authored and ndeloof committed Apr 16, 2024
1 parent ebc573b commit 5422e49
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
49 changes: 49 additions & 0 deletions loader/loader_yaml_test.go
Expand Up @@ -55,3 +55,52 @@ services:
},
})
}

func TestParseYAMLFilesMergeOverride(t *testing.T) {
model, err := loadYamlModel(context.TODO(), types.ConfigDetails{
ConfigFiles: []types.ConfigFile{
{Filename: "override.yaml",
Content: []byte(`
services:
base:
configs:
- source: credentials
target: /credentials/file1
x: &x
extends:
base
configs: !override
- source: credentials
target: /literally-anywhere-else
y:
<<: *x
configs:
credentials:
content: |
dummy value
`)},
}}, &Options{}, &cycleTracker{}, nil)
assert.NilError(t, err)
assert.DeepEqual(t, model, map[string]interface{}{
"configs": map[string]interface{}{"credentials": map[string]interface{}{"content": string("dummy value\n")}},
"services": map[string]interface{}{
"base": map[string]interface{}{
"configs": []interface{}{
map[string]interface{}{"source": string("credentials"), "target": string("/credentials/file1")},
},
},
"x": map[string]interface{}{
"configs": []interface{}{
map[string]interface{}{"source": string("credentials"), "target": string("/literally-anywhere-else")},
},
},
"y": map[string]interface{}{
"configs": []interface{}{
map[string]interface{}{"source": string("credentials"), "target": string("/literally-anywhere-else")},
},
},
},
})
}
10 changes: 2 additions & 8 deletions loader/reset.go
Expand Up @@ -42,14 +42,8 @@ func (p *ResetProcessor) UnmarshalYAML(value *yaml.Node) error {
// resolveReset detects `!reset` tag being set on yaml nodes and record position in the yaml tree
func (p *ResetProcessor) resolveReset(node *yaml.Node, path tree.Path) (*yaml.Node, error) {
// If the path contains "<<", removing the "<<" element and merging the path
if strings.Contains(path.String(), "<<") {
pathArr := strings.Split(path.String(), ".")
path = tree.NewPath(pathArr[0])
for _, el := range pathArr[1:] {
if el != "<<" {
path = tree.Path(strings.Join([]string{path.String(), el}, "."))
}
}
if strings.Contains(path.String(), ".<<") {
path = tree.NewPath(strings.Replace(path.String(), ".<<", "", 1))
}
// If the node is an alias, We need to process the alias field in order to consider the !override and !reset tags
if node.Kind == yaml.AliasNode {
Expand Down

0 comments on commit 5422e49

Please sign in to comment.