@@ -1289,7 +1289,7 @@ func TestReconcileOnCompletedTaskRun(t *testing.T) {
1289
1289
if err != nil {
1290
1290
t .Fatalf ("Expected completed TaskRun %s to exist but instead got error when getting it: %v" , taskRun .Name , err )
1291
1291
}
1292
- if d := cmp .Diff (newTr .Status .GetCondition (apis .ConditionSucceeded ), taskSt , ignoreLastTransitionTime ); d != "" {
1292
+ if d := cmp .Diff (taskSt , newTr .Status .GetCondition (apis .ConditionSucceeded ), ignoreLastTransitionTime ); d != "" {
1293
1293
t .Fatalf ("-want, +got: %v" , d )
1294
1294
}
1295
1295
}
@@ -1325,47 +1325,75 @@ func TestReconcileOnCancelledTaskRun(t *testing.T) {
1325
1325
Reason : "TaskRunCancelled" ,
1326
1326
Message : `TaskRun "test-taskrun-run-cancelled" was cancelled` ,
1327
1327
}
1328
- if d := cmp .Diff (newTr .Status .GetCondition (apis .ConditionSucceeded ), expectedStatus , ignoreLastTransitionTime ); d != "" {
1328
+ if d := cmp .Diff (expectedStatus , newTr .Status .GetCondition (apis .ConditionSucceeded ), ignoreLastTransitionTime ); d != "" {
1329
1329
t .Fatalf ("-want, +got: %v" , d )
1330
1330
}
1331
1331
}
1332
1332
1333
- func TestReconcileOnTimedOutTaskRun (t * testing.T ) {
1334
- taskRun := tb .TaskRun ("test-taskrun-timeout" , "foo" ,
1335
- tb .TaskRunSpec (
1336
- tb .TaskRunTaskRef (simpleTask .Name ),
1337
- tb .TaskRunTimeout (10 * time .Second ),
1338
- ),
1339
- tb .TaskRunStatus (tb .Condition (apis.Condition {
1340
- Type : apis .ConditionSucceeded ,
1341
- Status : corev1 .ConditionUnknown }),
1342
- tb .TaskRunStartTime (time .Now ().Add (- 15 * time .Second ))))
1343
-
1344
- d := test.Data {
1345
- TaskRuns : []* v1alpha1.TaskRun {taskRun },
1346
- Tasks : []* v1alpha1.Task {simpleTask },
1333
+ func TestReconcileTimeouts (t * testing.T ) {
1334
+ type testCase struct {
1335
+ taskRun * v1alpha1.TaskRun
1336
+ expectedStatus * apis.Condition
1347
1337
}
1348
1338
1349
- testAssets := getTaskRunController (t , d )
1350
- c := testAssets .Controller
1351
- clients := testAssets .Clients
1352
-
1353
- if err := c .Reconciler .Reconcile (context .Background (), fmt .Sprintf ("%s/%s" , taskRun .Namespace , taskRun .Name )); err != nil {
1354
- t .Fatalf ("Unexpected error when reconciling completed TaskRun : %v" , err )
1355
- }
1356
- newTr , err := clients .Pipeline .TektonV1alpha1 ().TaskRuns (taskRun .Namespace ).Get (taskRun .Name , metav1.GetOptions {})
1357
- if err != nil {
1358
- t .Fatalf ("Expected completed TaskRun %s to exist but instead got error when getting it: %v" , taskRun .Name , err )
1339
+ testcases := []testCase {
1340
+ {
1341
+ taskRun : tb .TaskRun ("test-taskrun-timeout" , "foo" ,
1342
+ tb .TaskRunSpec (
1343
+ tb .TaskRunTaskRef (simpleTask .Name ),
1344
+ tb .TaskRunTimeout (10 * time .Second ),
1345
+ ),
1346
+ tb .TaskRunStatus (tb .Condition (apis.Condition {
1347
+ Type : apis .ConditionSucceeded ,
1348
+ Status : corev1 .ConditionUnknown }),
1349
+ tb .TaskRunStartTime (time .Now ().Add (- 15 * time .Second )))),
1350
+
1351
+ expectedStatus : & apis.Condition {
1352
+ Type : apis .ConditionSucceeded ,
1353
+ Status : corev1 .ConditionFalse ,
1354
+ Reason : "TaskRunTimeout" ,
1355
+ Message : `TaskRun "test-taskrun-timeout" failed to finish within "10s"` ,
1356
+ },
1357
+ },
1358
+ {
1359
+ taskRun : tb .TaskRun ("test-taskrun-default-timeout-10-minutes" , "foo" ,
1360
+ tb .TaskRunSpec (
1361
+ tb .TaskRunTaskRef (simpleTask .Name ),
1362
+ ),
1363
+ tb .TaskRunStatus (tb .Condition (apis.Condition {
1364
+ Type : apis .ConditionSucceeded ,
1365
+ Status : corev1 .ConditionUnknown }),
1366
+ tb .TaskRunStartTime (time .Now ().Add (- 11 * time .Minute )))),
1367
+
1368
+ expectedStatus : & apis.Condition {
1369
+ Type : apis .ConditionSucceeded ,
1370
+ Status : corev1 .ConditionFalse ,
1371
+ Reason : "TaskRunTimeout" ,
1372
+ Message : `TaskRun "test-taskrun-default-timeout-10-minutes" failed to finish within "10m0s"` ,
1373
+ },
1374
+ },
1359
1375
}
1360
1376
1361
- expectedStatus := & apis.Condition {
1362
- Type : apis .ConditionSucceeded ,
1363
- Status : corev1 .ConditionFalse ,
1364
- Reason : "TaskRunTimeout" ,
1365
- Message : `TaskRun "test-taskrun-timeout" failed to finish within "10s"` ,
1366
- }
1367
- if d := cmp .Diff (newTr .Status .GetCondition (apis .ConditionSucceeded ), expectedStatus , ignoreLastTransitionTime ); d != "" {
1368
- t .Fatalf ("-want, +got: %v" , d )
1377
+ for _ , tc := range testcases {
1378
+ d := test.Data {
1379
+ TaskRuns : []* v1alpha1.TaskRun {tc .taskRun },
1380
+ Tasks : []* v1alpha1.Task {simpleTask },
1381
+ }
1382
+ testAssets := getTaskRunController (t , d )
1383
+ c := testAssets .Controller
1384
+ clients := testAssets .Clients
1385
+
1386
+ if err := c .Reconciler .Reconcile (context .Background (), fmt .Sprintf ("%s/%s" , tc .taskRun .Namespace , tc .taskRun .Name )); err != nil {
1387
+ t .Fatalf ("Unexpected error when reconciling completed TaskRun : %v" , err )
1388
+ }
1389
+ newTr , err := clients .Pipeline .TektonV1alpha1 ().TaskRuns (tc .taskRun .Namespace ).Get (tc .taskRun .Name , metav1.GetOptions {})
1390
+ if err != nil {
1391
+ t .Fatalf ("Expected completed TaskRun %s to exist but instead got error when getting it: %v" , tc .taskRun .Name , err )
1392
+ }
1393
+ condition := newTr .Status .GetCondition (apis .ConditionSucceeded )
1394
+ if d := cmp .Diff (tc .expectedStatus , condition , ignoreLastTransitionTime ); d != "" {
1395
+ t .Fatalf ("-want, +got: %v" , d )
1396
+ }
1369
1397
}
1370
1398
}
1371
1399
0 commit comments