Skip to content

Commit 3868ec4

Browse files
ndeloofglours
authored andcommitted
enforce unicity after canonical transformation
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 14ac0a9 commit 3868ec4

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

loader/extends_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,35 @@ services:
170170
})
171171
assert.NilError(t, err)
172172
}
173+
174+
func TestExtendsPortOverride(t *testing.T) {
175+
yaml := `
176+
name: test-extends-port
177+
services:
178+
test:
179+
extends:
180+
file: testdata/extends/ports.yaml
181+
service: test
182+
`
183+
abs, err := filepath.Abs(".")
184+
assert.NilError(t, err)
185+
186+
p, err := LoadWithContext(context.Background(), types.ConfigDetails{
187+
ConfigFiles: []types.ConfigFile{
188+
{
189+
Filename: "testdata/extends/ports.yaml",
190+
},
191+
{
192+
Content: []byte(yaml),
193+
Filename: "(override)",
194+
},
195+
},
196+
WorkingDir: abs,
197+
}, func(options *Options) {
198+
options.ResolvePaths = false
199+
options.SkipValidation = true
200+
})
201+
assert.NilError(t, err)
202+
assert.Equal(t, len(p.Services["test"].Ports), 1)
203+
204+
}

loader/loader.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
403403
return nil, err
404404
}
405405

406+
// Canonical transformation can reveal duplicates, typically as ports can be a range and conflict with an override
407+
dict, err = override.EnforceUnicity(dict)
408+
if err != nil {
409+
return nil, err
410+
}
411+
406412
if !opts.SkipInclude {
407413
included = append(included, config.ConfigFiles[0].Filename)
408414
err = ApplyInclude(ctx, config, dict, opts, included)

loader/testdata/extends/ports.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
test:
3+
image: test
4+
ports:
5+
- 8080:8080

0 commit comments

Comments
 (0)