Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reset): Add cycle detection fix for services that are prefixed with the name of a preceding service #704

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
},
)
}
}