@@ -52,6 +52,7 @@ services:
5252 abs , err := filepath .Abs ("." )
5353 assert .NilError (t , err )
5454
55+ extendsCount := 0
5556 p , err := LoadWithContext (context .Background (), types.ConfigDetails {
5657 ConfigFiles : []types.ConfigFile {
5758 {
@@ -60,11 +61,21 @@ services:
6061 },
6162 },
6263 WorkingDir : abs ,
64+ }, func (options * Options ) {
65+ options .ResolvePaths = false
66+ options .Listeners = []Listener {
67+ func (event string , metadata map [string ]any ) {
68+ if event == "extends" {
69+ extendsCount ++
70+ }
71+ },
72+ }
6373 })
6474 assert .NilError (t , err )
6575 assert .DeepEqual (t , p .Services ["test1" ].Hostname , "test1" )
6676 assert .Equal (t , p .Services ["test2" ].Hostname , "test2" )
6777 assert .Equal (t , p .Services ["test3" ].Hostname , "test3" )
78+ assert .Equal (t , extendsCount , 4 )
6879}
6980
7081func TestExtendsPort (t * testing.T ) {
@@ -262,6 +273,7 @@ services:
262273
263274 assert .NilError (t , os .WriteFile (filepath .Join (tmpdir , "compose.yaml" ), []byte (rootYAML ), 0o600 ))
264275
276+ extendsCount := 0
265277 actual , err := Load (types.ConfigDetails {
266278 WorkingDir : tmpdir ,
267279 ConfigFiles : []types.ConfigFile {{
@@ -272,6 +284,13 @@ services:
272284 options .SkipNormalization = true
273285 options .SkipConsistencyCheck = true
274286 options .SetProjectName ("project" , true )
287+ options .Listeners = []Listener {
288+ func (event string , metadata map [string ]any ) {
289+ if event == "extends" {
290+ extendsCount ++
291+ }
292+ },
293+ }
275294 })
276295 assert .NilError (t , err )
277296 assert .Assert (t , is .Len (actual .Services , 2 ))
@@ -283,6 +302,8 @@ services:
283302 svcB , err := actual .GetService ("out-service" )
284303 assert .NilError (t , err )
285304 assert .Equal (t , svcB .Build .Context , tmpdir )
305+
306+ assert .Equal (t , extendsCount , 3 )
286307}
287308
288309func TestRejectExtendsWithServiceRef (t * testing.T ) {
@@ -358,3 +379,84 @@ services:
358379 })
359380 }
360381}
382+
383+ func TestLoadExtendsListener (t * testing.T ) {
384+ yaml := `
385+ name: listener-extends
386+ services:
387+ foo:
388+ image: busybox
389+ extends: bar
390+ bar:
391+ image: alpine
392+ command: echo
393+ extends: wee
394+ wee:
395+ extends: last
396+ command: echo
397+ last:
398+ image: python`
399+ extendsCount := 0
400+ _ , err := Load (buildConfigDetails (yaml , nil ), func (options * Options ) {
401+ options .SkipConsistencyCheck = true
402+ options .SkipNormalization = true
403+ options .ResolvePaths = true
404+ options .Listeners = []Listener {
405+ func (event string , metadata map [string ]any ) {
406+ if event == "extends" {
407+ extendsCount ++
408+ }
409+ },
410+ }
411+ })
412+
413+ assert .NilError (t , err )
414+ assert .Equal (t , extendsCount , 3 )
415+ }
416+
417+ func TestLoadExtendsListenerMultipleFiles (t * testing.T ) {
418+ tmpdir := t .TempDir ()
419+ subDir := filepath .Join (tmpdir , "sub" )
420+ assert .NilError (t , os .Mkdir (subDir , 0o700 ))
421+ subYAML := `
422+ services:
423+ b:
424+ extends: c
425+ build:
426+ target: fake
427+ c:
428+ command: echo
429+ `
430+ assert .NilError (t , os .WriteFile (filepath .Join (tmpdir , "sub" , "compose.yaml" ), []byte (subYAML ), 0o600 ))
431+
432+ rootYAML := `
433+ services:
434+ a:
435+ extends:
436+ file: ./sub/compose.yaml
437+ service: b
438+ `
439+ assert .NilError (t , os .WriteFile (filepath .Join (tmpdir , "compose.yaml" ), []byte (rootYAML ), 0o600 ))
440+
441+ extendsCount := 0
442+ _ , err := Load (types.ConfigDetails {
443+ WorkingDir : tmpdir ,
444+ ConfigFiles : []types.ConfigFile {{
445+ Filename : filepath .Join (tmpdir , "compose.yaml" ),
446+ }},
447+ Environment : nil ,
448+ }, func (options * Options ) {
449+ options .SkipNormalization = true
450+ options .SkipConsistencyCheck = true
451+ options .SetProjectName ("project" , true )
452+ options .Listeners = []Listener {
453+ func (event string , metadata map [string ]any ) {
454+ if event == "extends" {
455+ extendsCount ++
456+ }
457+ },
458+ }
459+ })
460+ assert .NilError (t , err )
461+ assert .Equal (t , extendsCount , 2 )
462+ }
0 commit comments