17
17
package loader
18
18
19
19
import (
20
+ "fmt"
20
21
"strings"
21
22
"testing"
22
23
@@ -291,7 +292,7 @@ func TestValidateWatch(t *testing.T) {
291
292
Watch : []types.Trigger {
292
293
{
293
294
Action : types .WatchActionSync ,
294
- Path : "/app" ,
295
+ Path : [] string { "/app" } ,
295
296
Target : "/container/app" ,
296
297
},
297
298
},
@@ -303,69 +304,6 @@ func TestValidateWatch(t *testing.T) {
303
304
assert .NilError (t , err )
304
305
})
305
306
306
- t .Run ("watch missing target for sync action" , func (t * testing.T ) {
307
- project := types.Project {
308
- Services : types.Services {
309
- "myservice" : {
310
- Name : "myservice" ,
311
- Image : "scratch" ,
312
- Develop : & types.DevelopConfig {
313
- Watch : []types.Trigger {
314
- {
315
- Action : types .WatchActionSync ,
316
- Path : "/app" ,
317
- },
318
- },
319
- },
320
- },
321
- },
322
- }
323
- err := checkConsistency (& project )
324
- assert .Error (t , err , "services.myservice.develop.watch: target is required for non-rebuild actions: invalid compose project" )
325
- })
326
-
327
- t .Run ("watch missing target for sync+restart action" , func (t * testing.T ) {
328
- project := types.Project {
329
- Services : types.Services {
330
- "myservice" : {
331
- Name : "myservice" ,
332
- Image : "scratch" ,
333
- Develop : & types.DevelopConfig {
334
- Watch : []types.Trigger {
335
- {
336
- Action : types .WatchActionSyncRestart ,
337
- Path : "/app" ,
338
- },
339
- },
340
- },
341
- },
342
- },
343
- }
344
- err := checkConsistency (& project )
345
- assert .Error (t , err , "services.myservice.develop.watch: target is required for non-rebuild actions: invalid compose project" )
346
- })
347
-
348
- t .Run ("watch config valid with missing target for rebuild action" , func (t * testing.T ) {
349
- project := types.Project {
350
- Services : types.Services {
351
- "myservice" : {
352
- Name : "myservice" ,
353
- Image : "scratch" ,
354
- Develop : & types.DevelopConfig {
355
- Watch : []types.Trigger {
356
- {
357
- Action : types .WatchActionRebuild ,
358
- Path : "/app" ,
359
- },
360
- },
361
- },
362
- },
363
- },
364
- }
365
- err := checkConsistency (& project )
366
- assert .NilError (t , err )
367
- })
368
-
369
307
t .Run ("depends on disabled service" , func (t * testing.T ) {
370
308
project := types.Project {
371
309
Services : types.Services {
@@ -406,4 +344,109 @@ func TestValidateWatch(t *testing.T) {
406
344
err := checkConsistency (& project )
407
345
assert .ErrorContains (t , err , "depends on undefined service" )
408
346
})
347
+
348
+ type WatchActionTest struct {
349
+ action types.WatchAction
350
+ }
351
+ tests := []WatchActionTest {
352
+ {action : types .WatchActionSync },
353
+ {action : types .WatchActionSyncRestart },
354
+ {action : types .WatchActionSyncExec },
355
+ }
356
+ for _ , tt := range tests {
357
+ t .Run (fmt .Sprintf ("watch config is INVALID when missing target for %s action" , tt .action ), func (t * testing.T ) {
358
+ project := types.Project {
359
+ Services : types.Services {
360
+ "myservice" : {
361
+ Name : "myservice" ,
362
+ Image : "scratch" ,
363
+ Develop : & types.DevelopConfig {
364
+ Watch : []types.Trigger {
365
+ {
366
+ Action : tt .action ,
367
+ Path : []string {"/app" },
368
+ // Missing Target
369
+ },
370
+ },
371
+ },
372
+ },
373
+ },
374
+ }
375
+ err := checkConsistency (& project )
376
+ assert .Error (t , err , "services.myservice.develop.watch: target is required for sync, sync+exec and sync+restart actions: invalid compose project" )
377
+ })
378
+
379
+ t .Run (fmt .Sprintf ("watch config is INVALID with one or more paths for %s action" , tt .action ), func (t * testing.T ) {
380
+ project := types.Project {
381
+ Services : types.Services {
382
+ "myservice" : {
383
+ Name : "myservice" ,
384
+ Image : "scratch" ,
385
+ Develop : & types.DevelopConfig {
386
+ Watch : []types.Trigger {
387
+ {
388
+ Action : tt .action ,
389
+ Path : []string {"/app" , "/app2" }, // should only be one path
390
+ Target : "/container/app" ,
391
+ },
392
+ },
393
+ },
394
+ },
395
+ },
396
+ }
397
+ err := checkConsistency (& project )
398
+ assert .Error (t , err , "services.myservice.develop.watch: can only use more than one path for actions rebuild and restart: invalid compose project" )
399
+ })
400
+ }
401
+ tests = []WatchActionTest {
402
+ {action : types .WatchActionRebuild },
403
+ {action : types .WatchActionRestart },
404
+ }
405
+ for _ , tt := range tests {
406
+ t .Run (fmt .Sprintf ("watch config is VALID with missing target for %s action" , tt .action ), func (t * testing.T ) {
407
+ project := types.Project {
408
+ Services : types.Services {
409
+ "myservice" : {
410
+ Name : "myservice" ,
411
+ Image : "scratch" ,
412
+ Develop : & types.DevelopConfig {
413
+ Watch : []types.Trigger {
414
+ {
415
+ Action : tt .action ,
416
+ Path : []string {"/app" },
417
+ },
418
+ },
419
+ },
420
+ },
421
+ },
422
+ }
423
+ err := checkConsistency (& project )
424
+ assert .NilError (t , err )
425
+ })
426
+
427
+ t .Run (fmt .Sprintf ("watch config is VALID with one or more paths for %s action" , tt .action ), func (t * testing.T ) {
428
+ project := types.Project {
429
+ Services : types.Services {
430
+ "myservice" : {
431
+ Name : "myservice" ,
432
+ Image : "scratch" ,
433
+ Develop : & types.DevelopConfig {
434
+ Watch : []types.Trigger {
435
+ {
436
+ Action : tt .action ,
437
+ Path : []string {"/app" },
438
+ },
439
+ {
440
+ Action : tt .action ,
441
+ Path : []string {"/app" , "/app2" },
442
+ },
443
+ },
444
+ },
445
+ },
446
+ },
447
+ }
448
+ err := checkConsistency (& project )
449
+ assert .NilError (t , err )
450
+ })
451
+ }
409
452
}
0 commit comments