Skip to content

Commit

Permalink
fix(reset): Add cycle detection fix for services that are prefixed wi…
Browse files Browse the repository at this point in the history
…th the name of a preceding service

Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
  • Loading branch information
idsulik authored and glours committed Oct 30, 2024
1 parent 222d93c commit c2ef638
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
2 changes: 1 addition & 1 deletion loader/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p *ResetProcessor) resolveReset(node *yaml.Node, path tree.Path) (*yaml.No
}

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

// 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
77 changes: 63 additions & 14 deletions loader/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,71 @@ networks:
}

func TestResetCycle(t *testing.T) {
_, err := Load(
types.ConfigDetails{
ConfigFiles: []types.ConfigFile{
{
Filename: "(inline)",
Content: []byte(`
tests := []struct {
name string
config string
expectError bool
errorMsg string
}{
{
name: "no cycle",
config: `
name: test
services:
a: &a
image: alpine
a2: *a
`,
expectError: false,
errorMsg: "",
},
{
name: "no cycle reversed",
config: `
name: test
services:
a2: &a
image: alpine
a: *a
`,
expectError: false,
errorMsg: "",
},
{
name: "healthcheck_cycle",
config: `
x-healthcheck: &healthcheck
egress-service:
<<: *healthcheck
`),
},
},
}, func(options *Options) {
options.SkipNormalization = true
options.SkipConsistencyCheck = true
`,
expectError: true,
errorMsg: "cycle detected at path: x-healthcheck.egress-service",
},
)
assert.Error(t, err, "cycle detected at path: x-healthcheck.egress-service")
}

for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
_, err := Load(
types.ConfigDetails{
ConfigFiles: []types.ConfigFile{
{
Filename: "(inline)",
Content: []byte(tt.config),
},
},
}, func(options *Options) {
options.SkipNormalization = true
options.SkipConsistencyCheck = true
},
)

if tt.expectError {
assert.Error(t, err, tt.errorMsg)
} else {
assert.NilError(t, err)
}
},
)
}
}

0 comments on commit c2ef638

Please sign in to comment.