@@ -3097,7 +3097,8 @@ services:
30973097}
30983098
30993099func TestLoadDevelopConfig (t * testing.T ) {
3100- project , err := Load (buildConfigDetails (`
3100+ t .Run ("successfully load watch config" , func (t * testing.T ) {
3101+ project , err := Load (buildConfigDetails (`
31013102name: load-develop
31023103services:
31033104 frontend:
@@ -3112,7 +3113,6 @@ services:
31123113 target: /var/www
31133114 ignore:
31143115 - node_modules/
3115-
31163116 backend:
31173117 image: example/backend
31183118 build: ./backend
@@ -3123,7 +3123,6 @@ services:
31233123 path:
31243124 - ./backend/src
31253125 - ./backend
3126-
31273126 proxy:
31283127 image: example/proxy
31293128 build: ./proxy
@@ -3134,67 +3133,103 @@ services:
31343133 action: sync+restart
31353134 target: /etc/nginx/proxy.conf
31363135` , nil ), func (options * Options ) {
3137- options .ResolvePaths = false
3138- options .SkipValidation = true
3139- })
3140- assert .NilError (t , err )
3141- frontend , err := project .GetService ("frontend" )
3142- assert .NilError (t , err )
3143- assert .DeepEqual (t , * frontend .Develop , types.DevelopConfig {
3144- Watch : []types.Trigger {
3145- {
3146- Path : []string {"./webapp/html" },
3147- Action : types .WatchActionSync ,
3148- Target : "/var/www" ,
3149- Ignore : []string {"node_modules/" },
3150- Extensions : types.Extensions {
3151- "x-initialSync" : true ,
3136+ options .ResolvePaths = false
3137+ options .SkipValidation = true
3138+ })
3139+ assert .NilError (t , err )
3140+ frontend , err := project .GetService ("frontend" )
3141+ assert .NilError (t , err )
3142+ assert .DeepEqual (t , * frontend .Develop , types.DevelopConfig {
3143+ Watch : []types.Trigger {
3144+ {
3145+ Path : []string {"./webapp/html" },
3146+ Action : types .WatchActionSync ,
3147+ Target : "/var/www" ,
3148+ Ignore : []string {"node_modules/" },
3149+ Extensions : types.Extensions {
3150+ "x-initialSync" : true ,
3151+ },
31523152 },
31533153 },
3154- },
3155- } )
3156- backend , err := project . GetService ( "backend" )
3157- assert .NilError (t , err )
3158- assert . DeepEqual ( t , * backend . Develop , types.DevelopConfig {
3159- Watch : []types. Trigger {
3160- {
3161- Path : [] string { "./backend/src" , "./backend" } ,
3162- Action : types . WatchActionRebuild ,
3154+ })
3155+ backend , err := project . GetService ( "backend" )
3156+ assert . NilError ( t , err )
3157+ assert .DeepEqual (t , * backend . Develop , types. DevelopConfig {
3158+ Watch : [] types.Trigger {
3159+ {
3160+ Path : [] string { "./backend/src" , "./backend" },
3161+ Action : types . WatchActionRebuild ,
3162+ } ,
31633163 },
3164- },
3165- } )
3166- proxy , err := project . GetService ( "proxy" )
3167- assert .NilError (t , err )
3168- assert . DeepEqual ( t , * proxy . Develop , types.DevelopConfig {
3169- Watch : []types. Trigger {
3170- {
3171- Path : [] string { "./proxy/proxy.conf" } ,
3172- Action : types . WatchActionSyncRestart ,
3173- Target : "/etc/nginx/proxy.conf" ,
3164+ })
3165+ proxy , err := project . GetService ( "proxy" )
3166+ assert . NilError ( t , err )
3167+ assert .DeepEqual (t , * proxy . Develop , types. DevelopConfig {
3168+ Watch : [] types.Trigger {
3169+ {
3170+ Path : [] string { "./proxy/proxy.conf" },
3171+ Action : types . WatchActionSyncRestart ,
3172+ Target : "/etc/nginx/proxy.conf" ,
3173+ } ,
31743174 },
3175- },
3175+ })
31763176 })
3177- }
31783177
3179- func TestBadDevelopConfig (t * testing.T ) {
3180- _ , err := LoadWithContext (context .TODO (), buildConfigDetails (`
3178+ t . Run ( "should not load successfully bad watch config" , func (t * testing.T ) {
3179+ _ , err := LoadWithContext (context .TODO (), buildConfigDetails (`
31813180name: load-develop
31823181services:
31833182 frontend:
31843183 image: example/webapp
31853184 build: ./webapp
31863185 develop:
31873186 watch:
3188- # sync static content
3187+ # sync static content
31893188 - path: ./webapp/html
31903189 target: /var/www
31913190 ignore:
31923191 - node_modules/
3193-
31943192` , nil ), func (options * Options ) {
3195- options .ResolvePaths = false
3193+ options .ResolvePaths = false
3194+ })
3195+ assert .ErrorContains (t , err , "validating filename0.yml: services.frontend.develop.watch.0 action is required" )
3196+ })
3197+
3198+ t .Run ("should return an error when cannot resolve path" , func (t * testing.T ) {
3199+ b , err := os .ReadFile ("testdata/watch/compose-test-watch-star.yaml" )
3200+ assert .NilError (t , err )
3201+
3202+ configDetails := types.ConfigDetails {
3203+ WorkingDir : "testdata" ,
3204+ ConfigFiles : []types.ConfigFile {
3205+ {Filename : "watch/compose-test-watch-star.yaml" , Content : b },
3206+ },
3207+ Environment : map [string ]string {},
3208+ }
3209+ expServices := types.Services {
3210+ "app" : {
3211+ Name : "app" ,
3212+ Image : "example/app" ,
3213+ Environment : types.MappingWithEquals {},
3214+ Networks : map [string ]* types.ServiceNetworkConfig {"default" : nil },
3215+ Develop : & types.DevelopConfig {
3216+ Watch : []types.Trigger {
3217+ {
3218+ Path : []string {
3219+ "testdata/watch/other.txt" ,
3220+ "testdata/watch/some-text.txt" ,
3221+ },
3222+ Action : types .WatchActionRebuild ,
3223+ },
3224+ },
3225+ },
3226+ },
3227+ }
3228+
3229+ actual , err := Load (configDetails )
3230+ assert .NilError (t , err )
3231+ assert .DeepEqual (t , actual .Services , expServices )
31963232 })
3197- assert .ErrorContains (t , err , "validating filename0.yml: services.frontend.develop.watch.0 action is required" )
31983233}
31993234
32003235func TestBadServiceConfig (t * testing.T ) {
0 commit comments