@@ -361,6 +361,12 @@ func TestPipedConfig(t *testing.T) {
361361 },
362362 },
363363 },
364+ PlanPreview : PipedPlanPreview {
365+ WorkerNum : 5 ,
366+ CommandQueueBufferSize : 20 ,
367+ CommandCheckInterval : Duration (5 * time .Second ),
368+ CommandHandleTimeout : Duration (10 * time .Minute ),
369+ },
364370 },
365371 expectedError : nil ,
366372 },
@@ -378,6 +384,95 @@ func TestPipedConfig(t *testing.T) {
378384 }
379385}
380386
387+ func TestPipedPlanPreviewValidate (t * testing.T ) {
388+ testcases := []struct {
389+ name string
390+ planPreview PipedPlanPreview
391+ wantErr bool
392+ wantPipedPlanPreview PipedPlanPreview
393+ }{
394+ {
395+ name : "negative workerNum" ,
396+ wantErr : true ,
397+ planPreview : PipedPlanPreview {
398+ WorkerNum : - 1 ,
399+ },
400+ wantPipedPlanPreview : PipedPlanPreview {
401+ WorkerNum : - 1 ,
402+ },
403+ },
404+ {
405+ name : "negative commandQueueBufferSize" ,
406+ wantErr : true ,
407+ planPreview : PipedPlanPreview {
408+ CommandQueueBufferSize : - 1 ,
409+ },
410+ wantPipedPlanPreview : PipedPlanPreview {
411+ CommandQueueBufferSize : - 1 ,
412+ },
413+ },
414+ {
415+ name : "negative commandCheckInterval" ,
416+ wantErr : true ,
417+ planPreview : PipedPlanPreview {
418+ CommandCheckInterval : Duration (- time .Second ),
419+ },
420+ wantPipedPlanPreview : PipedPlanPreview {
421+ CommandCheckInterval : Duration (- time .Second ),
422+ },
423+ },
424+ {
425+ name : "negative commandHandleTimeout" ,
426+ wantErr : true ,
427+ planPreview : PipedPlanPreview {
428+ CommandHandleTimeout : Duration (- time .Minute ),
429+ },
430+ wantPipedPlanPreview : PipedPlanPreview {
431+ CommandHandleTimeout : Duration (- time .Minute ),
432+ },
433+ },
434+ {
435+ name : "all zero" ,
436+ wantErr : false ,
437+ planPreview : PipedPlanPreview {
438+ WorkerNum : 0 ,
439+ CommandQueueBufferSize : 0 ,
440+ CommandCheckInterval : Duration (0 ),
441+ CommandHandleTimeout : Duration (0 ),
442+ },
443+ wantPipedPlanPreview : PipedPlanPreview {
444+ WorkerNum : 0 ,
445+ CommandQueueBufferSize : 0 ,
446+ CommandCheckInterval : Duration (0 ),
447+ CommandHandleTimeout : Duration (0 ),
448+ },
449+ },
450+ {
451+ name : "valid values" ,
452+ wantErr : false ,
453+ planPreview : PipedPlanPreview {
454+ WorkerNum : 5 ,
455+ CommandQueueBufferSize : 20 ,
456+ CommandCheckInterval : Duration (5 * time .Second ),
457+ CommandHandleTimeout : Duration (10 * time .Minute ),
458+ },
459+ wantPipedPlanPreview : PipedPlanPreview {
460+ WorkerNum : 5 ,
461+ CommandQueueBufferSize : 20 ,
462+ CommandCheckInterval : Duration (5 * time .Second ),
463+ CommandHandleTimeout : Duration (10 * time .Minute ),
464+ },
465+ },
466+ }
467+ for _ , tc := range testcases {
468+ t .Run (tc .name , func (t * testing.T ) {
469+ err := tc .planPreview .Validate ()
470+ assert .Equal (t , tc .wantErr , err != nil )
471+ assert .Equal (t , tc .wantPipedPlanPreview , tc .planPreview )
472+ })
473+ }
474+ }
475+
381476func TestPipedEventWatcherValidate (t * testing.T ) {
382477 testcases := []struct {
383478 name string
@@ -1137,6 +1232,12 @@ func TestPipedSpecClone(t *testing.T) {
11371232 },
11381233 },
11391234 },
1235+ PlanPreview : PipedPlanPreview {
1236+ WorkerNum : 5 ,
1237+ CommandQueueBufferSize : 20 ,
1238+ CommandCheckInterval : Duration (5 * time .Second ),
1239+ CommandHandleTimeout : Duration (10 * time .Minute ),
1240+ },
11401241 },
11411242 expectedSpec : & PipedSpec {
11421243 ProjectID : "test-project" ,
@@ -1335,6 +1436,12 @@ func TestPipedSpecClone(t *testing.T) {
13351436 },
13361437 },
13371438 },
1439+ PlanPreview : PipedPlanPreview {
1440+ WorkerNum : 5 ,
1441+ CommandQueueBufferSize : 20 ,
1442+ CommandCheckInterval : Duration (5 * time .Second ),
1443+ CommandHandleTimeout : Duration (10 * time .Minute ),
1444+ },
13381445 },
13391446 expectedError : nil ,
13401447 },
0 commit comments