Skip to content

Commit c2ef638

Browse files
idsulikglours
authored andcommitted
fix(reset): Add cycle detection fix for services that are prefixed with the name of a preceding service
Signed-off-by: Suleiman Dibirov <[email protected]>
1 parent 222d93c commit c2ef638

File tree

2 files changed

+64
-15
lines changed

2 files changed

+64
-15
lines changed

loader/reset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (p *ResetProcessor) resolveReset(node *yaml.Node, path tree.Path) (*yaml.No
6363
}
6464

6565
// Mark the current node as visited
66-
p.visitedNodes[node] = pathStr
66+
p.visitedNodes[node] = pathStr + "."
6767

6868
// If the node is an alias, We need to process the alias field in order to consider the !override and !reset tags
6969
if node.Kind == yaml.AliasNode {

loader/reset_test.go

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,71 @@ networks:
8383
}
8484

8585
func TestResetCycle(t *testing.T) {
86-
_, err := Load(
87-
types.ConfigDetails{
88-
ConfigFiles: []types.ConfigFile{
89-
{
90-
Filename: "(inline)",
91-
Content: []byte(`
86+
tests := []struct {
87+
name string
88+
config string
89+
expectError bool
90+
errorMsg string
91+
}{
92+
{
93+
name: "no cycle",
94+
config: `
95+
name: test
96+
services:
97+
a: &a
98+
image: alpine
99+
a2: *a
100+
`,
101+
expectError: false,
102+
errorMsg: "",
103+
},
104+
{
105+
name: "no cycle reversed",
106+
config: `
107+
name: test
108+
services:
109+
a2: &a
110+
image: alpine
111+
a: *a
112+
`,
113+
expectError: false,
114+
errorMsg: "",
115+
},
116+
{
117+
name: "healthcheck_cycle",
118+
config: `
92119
x-healthcheck: &healthcheck
93120
egress-service:
94121
<<: *healthcheck
95-
`),
96-
},
97-
},
98-
}, func(options *Options) {
99-
options.SkipNormalization = true
100-
options.SkipConsistencyCheck = true
122+
`,
123+
expectError: true,
124+
errorMsg: "cycle detected at path: x-healthcheck.egress-service",
101125
},
102-
)
103-
assert.Error(t, err, "cycle detected at path: x-healthcheck.egress-service")
126+
}
127+
128+
for _, tt := range tests {
129+
t.Run(
130+
tt.name, func(t *testing.T) {
131+
_, err := Load(
132+
types.ConfigDetails{
133+
ConfigFiles: []types.ConfigFile{
134+
{
135+
Filename: "(inline)",
136+
Content: []byte(tt.config),
137+
},
138+
},
139+
}, func(options *Options) {
140+
options.SkipNormalization = true
141+
options.SkipConsistencyCheck = true
142+
},
143+
)
144+
145+
if tt.expectError {
146+
assert.Error(t, err, tt.errorMsg)
147+
} else {
148+
assert.NilError(t, err)
149+
}
150+
},
151+
)
152+
}
104153
}

0 commit comments

Comments
 (0)