Skip to content

Commit 5422e49

Browse files
arankeparthndeloof
authored andcommitted
incorporating review comments
Signed-off-by: parth aranke <[email protected]>
1 parent ebc573b commit 5422e49

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

loader/loader_yaml_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,52 @@ services:
5555
},
5656
})
5757
}
58+
59+
func TestParseYAMLFilesMergeOverride(t *testing.T) {
60+
model, err := loadYamlModel(context.TODO(), types.ConfigDetails{
61+
ConfigFiles: []types.ConfigFile{
62+
{Filename: "override.yaml",
63+
Content: []byte(`
64+
services:
65+
base:
66+
configs:
67+
- source: credentials
68+
target: /credentials/file1
69+
x: &x
70+
extends:
71+
base
72+
configs: !override
73+
- source: credentials
74+
target: /literally-anywhere-else
75+
76+
y:
77+
<<: *x
78+
79+
configs:
80+
credentials:
81+
content: |
82+
dummy value
83+
`)},
84+
}}, &Options{}, &cycleTracker{}, nil)
85+
assert.NilError(t, err)
86+
assert.DeepEqual(t, model, map[string]interface{}{
87+
"configs": map[string]interface{}{"credentials": map[string]interface{}{"content": string("dummy value\n")}},
88+
"services": map[string]interface{}{
89+
"base": map[string]interface{}{
90+
"configs": []interface{}{
91+
map[string]interface{}{"source": string("credentials"), "target": string("/credentials/file1")},
92+
},
93+
},
94+
"x": map[string]interface{}{
95+
"configs": []interface{}{
96+
map[string]interface{}{"source": string("credentials"), "target": string("/literally-anywhere-else")},
97+
},
98+
},
99+
"y": map[string]interface{}{
100+
"configs": []interface{}{
101+
map[string]interface{}{"source": string("credentials"), "target": string("/literally-anywhere-else")},
102+
},
103+
},
104+
},
105+
})
106+
}

loader/reset.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,8 @@ func (p *ResetProcessor) UnmarshalYAML(value *yaml.Node) error {
4242
// resolveReset detects `!reset` tag being set on yaml nodes and record position in the yaml tree
4343
func (p *ResetProcessor) resolveReset(node *yaml.Node, path tree.Path) (*yaml.Node, error) {
4444
// If the path contains "<<", removing the "<<" element and merging the path
45-
if strings.Contains(path.String(), "<<") {
46-
pathArr := strings.Split(path.String(), ".")
47-
path = tree.NewPath(pathArr[0])
48-
for _, el := range pathArr[1:] {
49-
if el != "<<" {
50-
path = tree.Path(strings.Join([]string{path.String(), el}, "."))
51-
}
52-
}
45+
if strings.Contains(path.String(), ".<<") {
46+
path = tree.NewPath(strings.Replace(path.String(), ".<<", "", 1))
5347
}
5448
// If the node is an alias, We need to process the alias field in order to consider the !override and !reset tags
5549
if node.Kind == yaml.AliasNode {

0 commit comments

Comments
 (0)