Skip to content

Commit

Permalink
enforce unicity after canonical transformation
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof authored and glours committed Feb 6, 2024
1 parent 14ac0a9 commit 3868ec4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
32 changes: 32 additions & 0 deletions loader/extends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,35 @@ services:
})
assert.NilError(t, err)
}

func TestExtendsPortOverride(t *testing.T) {
yaml := `
name: test-extends-port
services:
test:
extends:
file: testdata/extends/ports.yaml
service: test
`
abs, err := filepath.Abs(".")
assert.NilError(t, err)

p, err := LoadWithContext(context.Background(), types.ConfigDetails{
ConfigFiles: []types.ConfigFile{
{
Filename: "testdata/extends/ports.yaml",
},
{
Content: []byte(yaml),
Filename: "(override)",
},
},
WorkingDir: abs,
}, func(options *Options) {
options.ResolvePaths = false
options.SkipValidation = true
})
assert.NilError(t, err)
assert.Equal(t, len(p.Services["test"].Ports), 1)

}
6 changes: 6 additions & 0 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
return nil, err
}

// Canonical transformation can reveal duplicates, typically as ports can be a range and conflict with an override
dict, err = override.EnforceUnicity(dict)
if err != nil {
return nil, err
}

if !opts.SkipInclude {
included = append(included, config.ConfigFiles[0].Filename)
err = ApplyInclude(ctx, config, dict, opts, included)
Expand Down
5 changes: 5 additions & 0 deletions loader/testdata/extends/ports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
test:
image: test
ports:
- 8080:8080

0 comments on commit 3868ec4

Please sign in to comment.