@@ -798,6 +798,37 @@ services:
798798 })
799799}
800800
801+ func TestServiceContext (t * testing.T ) {
802+ dt := []byte (`
803+ services:
804+ base:
805+ build:
806+ dockerfile: baseapp.Dockerfile
807+ command: ./entrypoint.sh
808+ webapp:
809+ build:
810+ context: ./dir
811+ additional_contexts:
812+ base: service:base
813+ ` )
814+
815+ c , err := ParseCompose ([]composetypes.ConfigFile {{Content : dt }}, nil )
816+ require .NoError (t , err )
817+
818+ require .Equal (t , 1 , len (c .Groups ))
819+ require .Equal (t , "default" , c .Groups [0 ].Name )
820+ sort .Strings (c .Groups [0 ].Targets )
821+ require .Equal (t , []string {"base" , "webapp" }, c .Groups [0 ].Targets )
822+
823+ require .Equal (t , 2 , len (c .Targets ))
824+ sort .Slice (c .Targets , func (i , j int ) bool {
825+ return c .Targets [i ].Name < c .Targets [j ].Name
826+ })
827+
828+ require .Equal (t , "webapp" , c .Targets [1 ].Name )
829+ require .Equal (t , map [string ]string {"base" : "target:base" }, c .Targets [1 ].Contexts )
830+ }
831+
801832// chdir changes the current working directory to the named directory,
802833// and then restore the original working directory at the end of the test.
803834func chdir (t * testing.T , dir string ) {
0 commit comments