@@ -3051,7 +3051,8 @@ services:
3051
3051
}
3052
3052
3053
3053
func TestLoadDevelopConfig (t * testing.T ) {
3054
- project , err := LoadWithContext (context .TODO (), buildConfigDetails (`
3054
+ t .Run ("successfully load watch config" , func (t * testing.T ) {
3055
+ project , err := LoadWithContext (context .Background (), buildConfigDetails (`
3055
3056
name: load-develop
3056
3057
services:
3057
3058
frontend:
@@ -3066,7 +3067,6 @@ services:
3066
3067
target: /var/www
3067
3068
ignore:
3068
3069
- node_modules/
3069
-
3070
3070
backend:
3071
3071
image: example/backend
3072
3072
build: ./backend
@@ -3077,7 +3077,6 @@ services:
3077
3077
path:
3078
3078
- ./backend/src
3079
3079
- ./backend
3080
-
3081
3080
proxy:
3082
3081
image: example/proxy
3083
3082
build: ./proxy
@@ -3088,67 +3087,103 @@ services:
3088
3087
action: sync+restart
3089
3088
target: /etc/nginx/proxy.conf
3090
3089
` , nil ), func (options * Options ) {
3091
- options .ResolvePaths = false
3092
- options .SkipValidation = true
3093
- })
3094
- assert .NilError (t , err )
3095
- frontend , err := project .GetService ("frontend" )
3096
- assert .NilError (t , err )
3097
- assert .DeepEqual (t , * frontend .Develop , types.DevelopConfig {
3098
- Watch : []types.Trigger {
3099
- {
3100
- Path : []string {"./webapp/html" },
3101
- Action : types .WatchActionSync ,
3102
- Target : "/var/www" ,
3103
- Ignore : []string {"node_modules/" },
3104
- Extensions : types.Extensions {
3105
- "x-initialSync" : true ,
3090
+ options .ResolvePaths = false
3091
+ options .SkipValidation = true
3092
+ })
3093
+ assert .NilError (t , err )
3094
+ frontend , err := project .GetService ("frontend" )
3095
+ assert .NilError (t , err )
3096
+ assert .DeepEqual (t , * frontend .Develop , types.DevelopConfig {
3097
+ Watch : []types.Trigger {
3098
+ {
3099
+ Path : []string {"./webapp/html" },
3100
+ Action : types .WatchActionSync ,
3101
+ Target : "/var/www" ,
3102
+ Ignore : []string {"node_modules/" },
3103
+ Extensions : types.Extensions {
3104
+ "x-initialSync" : true ,
3105
+ },
3106
3106
},
3107
3107
},
3108
- },
3109
- } )
3110
- backend , err := project . GetService ( "backend" )
3111
- assert .NilError (t , err )
3112
- assert . DeepEqual ( t , * backend . Develop , types.DevelopConfig {
3113
- Watch : []types. Trigger {
3114
- {
3115
- Path : [] string { "./backend/src" , "./backend" } ,
3116
- Action : types . WatchActionRebuild ,
3108
+ })
3109
+ backend , err := project . GetService ( "backend" )
3110
+ assert . NilError ( t , err )
3111
+ assert .DeepEqual (t , * backend . Develop , types. DevelopConfig {
3112
+ Watch : [] types.Trigger {
3113
+ {
3114
+ Path : [] string { "./backend/src" , "./backend" },
3115
+ Action : types . WatchActionRebuild ,
3116
+ } ,
3117
3117
},
3118
- },
3119
- } )
3120
- proxy , err := project . GetService ( "proxy" )
3121
- assert .NilError (t , err )
3122
- assert . DeepEqual ( t , * proxy . Develop , types.DevelopConfig {
3123
- Watch : []types. Trigger {
3124
- {
3125
- Path : [] string { "./proxy/proxy.conf" } ,
3126
- Action : types . WatchActionSyncRestart ,
3127
- Target : "/etc/nginx/proxy.conf" ,
3118
+ })
3119
+ proxy , err := project . GetService ( "proxy" )
3120
+ assert . NilError ( t , err )
3121
+ assert .DeepEqual (t , * proxy . Develop , types. DevelopConfig {
3122
+ Watch : [] types.Trigger {
3123
+ {
3124
+ Path : [] string { "./proxy/proxy.conf" },
3125
+ Action : types . WatchActionSyncRestart ,
3126
+ Target : "/etc/nginx/proxy.conf" ,
3127
+ } ,
3128
3128
},
3129
- },
3129
+ })
3130
3130
})
3131
- }
3132
3131
3133
- func TestBadDevelopConfig (t * testing.T ) {
3134
- _ , err := LoadWithContext (context .TODO (), buildConfigDetails (`
3132
+ t . Run ( "should not load successfully bad watch config" , func (t * testing.T ) {
3133
+ _ , err := LoadWithContext (context .TODO (), buildConfigDetails (`
3135
3134
name: load-develop
3136
3135
services:
3137
3136
frontend:
3138
3137
image: example/webapp
3139
3138
build: ./webapp
3140
3139
develop:
3141
3140
watch:
3142
- # sync static content
3141
+ # sync static content
3143
3142
- path: ./webapp/html
3144
3143
target: /var/www
3145
3144
ignore:
3146
3145
- node_modules/
3147
-
3148
3146
` , nil ), func (options * Options ) {
3149
- options .ResolvePaths = false
3147
+ options .ResolvePaths = false
3148
+ })
3149
+ assert .ErrorContains (t , err , "validating filename0.yml: services.frontend.develop.watch.0 action is required" )
3150
+ })
3151
+
3152
+ t .Run ("should return an error when cannot resolve path" , func (t * testing.T ) {
3153
+ b , err := os .ReadFile ("testdata/watch/compose-test-watch-star.yaml" )
3154
+ assert .NilError (t , err )
3155
+
3156
+ configDetails := types.ConfigDetails {
3157
+ WorkingDir : "testdata" ,
3158
+ ConfigFiles : []types.ConfigFile {
3159
+ {Filename : "watch/compose-test-watch-star.yaml" , Content : b },
3160
+ },
3161
+ Environment : map [string ]string {},
3162
+ }
3163
+ expServices := types.Services {
3164
+ "app" : {
3165
+ Name : "app" ,
3166
+ Image : "example/app" ,
3167
+ Environment : types.MappingWithEquals {},
3168
+ Networks : map [string ]* types.ServiceNetworkConfig {"default" : nil },
3169
+ Develop : & types.DevelopConfig {
3170
+ Watch : []types.Trigger {
3171
+ {
3172
+ Path : []string {
3173
+ filepath .FromSlash ("testdata/watch/other.txt" ),
3174
+ filepath .FromSlash ("testdata/watch/some-text.txt" ),
3175
+ },
3176
+ Action : types .WatchActionRebuild ,
3177
+ },
3178
+ },
3179
+ },
3180
+ },
3181
+ }
3182
+
3183
+ actual , err := LoadWithContext (context .Background (), configDetails )
3184
+ assert .NilError (t , err )
3185
+ assert .DeepEqual (t , actual .Services , expServices )
3150
3186
})
3151
- assert .ErrorContains (t , err , "validating filename0.yml: services.frontend.develop.watch.0 action is required" )
3152
3187
}
3153
3188
3154
3189
func TestBadServiceConfig (t * testing.T ) {
0 commit comments