@@ -184,7 +184,15 @@ func TestReconcile(t *testing.T) {
184
184
),
185
185
tb .TaskRunLabel ("pipeline.knative.dev/pipeline" , "test-pipeline" ),
186
186
tb .TaskRunLabel ("pipeline.knative.dev/pipelineRun" , "test-pipeline-run-success" ),
187
- tb .TaskRunSpec (tb .TaskRunTaskRef ("unit-test-task" ),
187
+ tb .TaskRunSpec (tb .TaskRunTaskSpec (
188
+ tb .TaskInputs (
189
+ tb .InputsResource ("workspace" , v1alpha1 .PipelineResourceTypeGit ),
190
+ tb .InputsParam ("foo" ), tb .InputsParam ("bar" ), tb .InputsParam ("templatedparam" ),
191
+ ),
192
+ tb .TaskOutputs (
193
+ tb .OutputsResource ("image-to-use" , v1alpha1 .PipelineResourceTypeImage ),
194
+ tb .OutputsResource ("workspace" , v1alpha1 .PipelineResourceTypeGit ),
195
+ )),
188
196
tb .TaskRunServiceAccount ("test-sa" ),
189
197
tb .TaskRunInputs (
190
198
tb .TaskRunInputsParam ("foo" , "somethingfun" ),
@@ -425,8 +433,7 @@ func TestReconcileOnCompletedPipelineRun(t *testing.T) {
425
433
})),
426
434
)}
427
435
ps := []* v1alpha1.Pipeline {tb .Pipeline ("test-pipeline" , "foo" , tb .PipelineSpec (
428
- tb .PipelineTask ("hello-world-1" , "hellow-world" ),
429
- ))}
436
+ tb .PipelineTask ("hello-world-1" , "hellow-world" )))}
430
437
ts := []* v1alpha1.Task {tb .Task ("hello-world" , "foo" )}
431
438
d := test.Data {
432
439
PipelineRuns : prs ,
@@ -496,6 +503,7 @@ func TestReconcileOnCancelledPipelineRun(t *testing.T) {
496
503
),
497
504
),
498
505
}
506
+
499
507
d := test.Data {
500
508
PipelineRuns : prs ,
501
509
Pipelines : ps ,
@@ -517,12 +525,69 @@ func TestReconcileOnCancelledPipelineRun(t *testing.T) {
517
525
518
526
// Check that the PipelineRun was reconciled correctly
519
527
reconciledRun , err := clients .Pipeline .Pipeline ().PipelineRuns ("foo" ).Get ("test-pipeline-run-cancelled" , metav1.GetOptions {})
520
- if err != nil {
521
- t .Fatalf ("Somehow had error getting completed reconciled run out of fake client: %s" , err )
522
- }
523
528
524
529
// This PipelineRun should still be complete and false, and the status should reflect that
525
530
if ! reconciledRun .Status .GetCondition (duckv1alpha1 .ConditionSucceeded ).IsFalse () {
526
531
t .Errorf ("Expected PipelineRun status to be complete and false, but was %v" , reconciledRun .Status .GetCondition (duckv1alpha1 .ConditionSucceeded ))
527
532
}
528
533
}
534
+
535
+ func TestReconcileWithTimeout (t * testing.T ) {
536
+ ps := []* v1alpha1.Pipeline {tb .Pipeline ("test-pipeline" , "foo" , tb .PipelineSpec (
537
+ tb .PipelineTask ("hello-world-1" , "hello-world" ),
538
+ tb .PipelineTimeout (& metav1.Duration {Duration : 12 * time .Hour }),
539
+ ))}
540
+ prs := []* v1alpha1.PipelineRun {tb .PipelineRun ("test-pipeline-run-with-timeout" , "foo" ,
541
+ tb .PipelineRunSpec ("test-pipeline" ,
542
+ tb .PipelineRunServiceAccount ("test-sa" ),
543
+ ),
544
+ tb .PipelineRunStatus (
545
+ tb .PipelineRunStartTime (time .Now ().AddDate (0 , 0 , - 1 ))),
546
+ )}
547
+ ts := []* v1alpha1.Task {tb .Task ("hello-world" , "foo" )}
548
+
549
+ d := test.Data {
550
+ PipelineRuns : prs ,
551
+ Pipelines : ps ,
552
+ Tasks : ts ,
553
+ }
554
+
555
+ // create fake recorder for testing
556
+ fr := record .NewFakeRecorder (2 )
557
+
558
+ testAssets := getPipelineRunController (d , fr )
559
+ c := testAssets .Controller
560
+ clients := testAssets .Clients
561
+
562
+ err := c .Reconciler .Reconcile (context .Background (), "foo/test-pipeline-run-with-timeout" )
563
+ if err != nil {
564
+ t .Errorf ("Did not expect to see error when reconciling completed PipelineRun but saw %s" , err )
565
+ }
566
+
567
+ // Check that the PipelineRun was reconciled correctly
568
+ reconciledRun , err := clients .Pipeline .Pipeline ().PipelineRuns ("foo" ).Get ("test-pipeline-run-with-timeout" , metav1.GetOptions {})
569
+ if err != nil {
570
+ t .Fatalf ("Somehow had error getting completed reconciled run out of fake client: %s" , err )
571
+ }
572
+
573
+ // The PipelineRun should be timed out.
574
+ if reconciledRun .Status .GetCondition (duckv1alpha1 .ConditionSucceeded ).Reason != resources .ReasonTimedOut {
575
+ t .Errorf ("Expected PipelineRun to be timed out, but condition reason is %s" , reconciledRun .Status .GetCondition (duckv1alpha1 .ConditionSucceeded ))
576
+ }
577
+
578
+ // Check that the expected TaskRun was created
579
+ actual := clients .Pipeline .Actions ()[0 ].(ktesting.CreateAction ).GetObject ().(* v1alpha1.TaskRun )
580
+ if actual == nil {
581
+ t .Errorf ("Expected a TaskRun to be created, but it wasn't." )
582
+ }
583
+
584
+ // There should be a time out for the TaskRun
585
+ if actual .Spec .TaskSpec .Timeout == nil {
586
+ t .Fatalf ("TaskSpec.Timeout shouldn't be nil" )
587
+ }
588
+
589
+ // The TaskRun timeout should be less than or equal to the PipelineRun timeout.
590
+ if actual .Spec .TaskSpec .Timeout .Duration > ps [0 ].Spec .Timeout .Duration {
591
+ t .Errorf ("TaskRun timeout %s should be less than or equal to PipelineRun timeout %s" , actual .Spec .TaskSpec .Timeout .Duration .String (), ps [0 ].Spec .Timeout .Duration .String ())
592
+ }
593
+ }
0 commit comments