Skip to content

Commit

Permalink
Fix invalid test cases
Browse files Browse the repository at this point in the history
Fixes test cases using certain combinations of values that would not occur during real execution:

 - Incomplete TaskRuns won't have a CompletionTime, and the Status would be Unknown.
 - Successful TaskRuns should have a CompletionTime.
  • Loading branch information
colinodell committed Sep 8, 2022
1 parent 8aa0ead commit abb5704
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions pkg/cmd/taskrun/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,12 @@ func TestTaskRunDelete(t *testing.T) {
},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
CompletionTime: &metav1.Time{
Time: clock.Now().Add(10 * time.Minute),
},
CompletionTime: nil,
},
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Status: corev1.ConditionTrue,
Status: corev1.ConditionUnknown,
Reason: v1beta1.TaskRunReasonStarted.String(),
},
},
Expand All @@ -358,14 +356,12 @@ func TestTaskRunDelete(t *testing.T) {
},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
CompletionTime: &metav1.Time{
Time: clock.Now().Add(10 * time.Minute),
},
CompletionTime: nil,
},
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Status: corev1.ConditionTrue,
Status: corev1.ConditionUnknown,
Reason: v1beta1.TaskRunReasonRunning.String(),
},
},
Expand All @@ -386,15 +382,12 @@ func TestTaskRunDelete(t *testing.T) {
},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
CompletionTime: &metav1.Time{
// Use real time for testing keep-since and keep together
Time: time.Now(),
},
CompletionTime: nil,
},
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Status: corev1.ConditionTrue,
Status: corev1.ConditionUnknown,
Reason: v1beta1.TaskRunReasonStarted.String(),
},
},
Expand All @@ -415,15 +408,12 @@ func TestTaskRunDelete(t *testing.T) {
},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
CompletionTime: &metav1.Time{
// Use real time for testing keep-since and keep together
Time: time.Now(),
},
CompletionTime: nil,
},
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Status: corev1.ConditionTrue,
Status: corev1.ConditionUnknown,
Reason: v1beta1.TaskRunReasonRunning.String(),
},
},
Expand Down Expand Up @@ -912,6 +902,11 @@ func Test_ClusterTask_TaskRuns_Not_Deleted_With_Task_Option(t *testing.T) {
},
},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
CompletionTime: &metav1.Time{
Time: time.Now(),
},
},
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Expand Down Expand Up @@ -941,6 +936,11 @@ func Test_ClusterTask_TaskRuns_Not_Deleted_With_Task_Option(t *testing.T) {
},
},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
CompletionTime: &metav1.Time{
Time: time.Now(),
},
},
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Expand Down Expand Up @@ -1027,6 +1027,11 @@ func Test_Task_TaskRuns_Not_Deleted_With_ClusterTask_Option(t *testing.T) {
},
},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
CompletionTime: &metav1.Time{
Time: time.Now(),
},
},
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Expand Down Expand Up @@ -1056,6 +1061,11 @@ func Test_Task_TaskRuns_Not_Deleted_With_ClusterTask_Option(t *testing.T) {
},
},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
CompletionTime: &metav1.Time{
Time: time.Now(),
},
},
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Expand Down

0 comments on commit abb5704

Please sign in to comment.