Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TestIsSkipped to allow checking multiple tasks #3471

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 85 additions & 67 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,10 @@ func TestIsSkipped(t *testing.T) {

tcs := []struct {
name string
taskName string
state PipelineRunState
expected bool
expected map[string]bool
}{{
name: "tasks-condition-passed",
taskName: "mytask1",
name: "tasks-condition-passed",
state: PipelineRunState{{
PipelineTask: &pts[0],
TaskRunName: "pipelinerun-conditionaltask",
Expand All @@ -554,10 +552,11 @@ func TestIsSkipped(t *testing.T) {
},
ResolvedConditionChecks: successTaskConditionCheckState,
}},
expected: false,
expected: map[string]bool{
"mytask1": false,
},
}, {
name: "tasks-condition-failed",
taskName: "mytask1",
name: "tasks-condition-failed",
state: PipelineRunState{{
PipelineTask: &pts[0],
TaskRunName: "pipelinerun-conditionaltask",
Expand All @@ -567,10 +566,11 @@ func TestIsSkipped(t *testing.T) {
},
ResolvedConditionChecks: failedTaskConditionCheckState,
}},
expected: true,
expected: map[string]bool{
"mytask1": true,
},
}, {
name: "tasks-multiple-conditions-passed-failed",
taskName: "mytask1",
name: "tasks-multiple-conditions-passed-failed",
state: PipelineRunState{{
PipelineTask: &pts[0],
TaskRunName: "pipelinerun-conditionaltask",
Expand All @@ -588,15 +588,17 @@ func TestIsSkipped(t *testing.T) {
ConditionCheck: v1beta1.NewConditionCheck(makeSucceeded(conditionChecks[0])),
}},
}},
expected: true,
expected: map[string]bool{
"mytask1": true,
},
}, {
name: "tasks-condition-running",
taskName: "mytask6",
state: conditionCheckStartedState,
expected: false,
name: "tasks-condition-running",
state: conditionCheckStartedState,
expected: map[string]bool{
"mytask6": false,
},
}, {
name: "tasks-parent-condition-passed",
taskName: "mytask7",
name: "tasks-parent-condition-passed",
state: PipelineRunState{{
PipelineTask: &pts[5],
TaskRunName: "pipelinerun-conditionaltask",
Expand All @@ -608,10 +610,11 @@ func TestIsSkipped(t *testing.T) {
}, {
PipelineTask: &pts[6],
}},
expected: false,
expected: map[string]bool{
"mytask7": false,
},
}, {
name: "tasks-parent-condition-failed",
taskName: "mytask7",
name: "tasks-parent-condition-failed",
state: PipelineRunState{{
PipelineTask: &pts[5],
TaskRunName: "pipelinerun-conditionaltask",
Expand All @@ -623,10 +626,11 @@ func TestIsSkipped(t *testing.T) {
}, {
PipelineTask: &pts[6],
}},
expected: true,
expected: map[string]bool{
"mytask7": true,
},
}, {
name: "tasks-parent-condition-running",
taskName: "mytask7",
name: "tasks-parent-condition-running",
state: PipelineRunState{{
PipelineTask: &pts[5],
TaskRunName: "pipelinerun-conditionaltask",
Expand All @@ -642,25 +646,29 @@ func TestIsSkipped(t *testing.T) {
}, {
PipelineTask: &pts[6],
}},
expected: false,
expected: map[string]bool{
"mytask7": false,
},
}, {
name: "tasks-failed",
taskName: "mytask1",
state: oneFailedState,
expected: false,
name: "tasks-failed",
state: oneFailedState,
expected: map[string]bool{
"mytask1": false,
},
}, {
name: "tasks-passed",
taskName: "mytask1",
state: oneFinishedState,
expected: false,
name: "tasks-passed",
state: oneFinishedState,
expected: map[string]bool{
"mytask1": false,
},
}, {
name: "tasks-cancelled",
taskName: "mytask5",
state: taskCancelled,
expected: false,
name: "tasks-cancelled",
state: taskCancelled,
expected: map[string]bool{
"mytask5": false,
},
}, {
name: "tasks-parent-failed",
taskName: "mytask7",
name: "tasks-parent-failed",
state: PipelineRunState{{
PipelineTask: &pts[5],
TaskRunName: "pipelinerun-mytask1",
Expand All @@ -676,10 +684,11 @@ func TestIsSkipped(t *testing.T) {
TaskSpec: &task.Spec,
},
}},
expected: true,
expected: map[string]bool{
"mytask7": true,
},
}, {
name: "tasks-parent-cancelled",
taskName: "mytask7",
name: "tasks-parent-cancelled",
state: PipelineRunState{{
PipelineTask: &pts[5],
TaskRunName: "pipelinerun-mytask1",
Expand All @@ -695,10 +704,11 @@ func TestIsSkipped(t *testing.T) {
TaskSpec: &task.Spec,
},
}},
expected: true,
expected: map[string]bool{
"mytask7": true,
},
}, {
name: "tasks-grandparent-failed",
taskName: "mytask10",
name: "tasks-grandparent-failed",
state: PipelineRunState{{
PipelineTask: &pts[5],
TaskRunName: "pipelinerun-mytask1",
Expand All @@ -725,10 +735,11 @@ func TestIsSkipped(t *testing.T) {
TaskSpec: &task.Spec,
},
}},
expected: true,
expected: map[string]bool{
"mytask10": true,
},
}, {
name: "tasks-parents-failed-passed",
taskName: "mytask8",
name: "tasks-parents-failed-passed",
state: PipelineRunState{{
PipelineTask: &pts[5],
TaskRunName: "pipelinerun-mytask1",
Expand All @@ -751,10 +762,11 @@ func TestIsSkipped(t *testing.T) {
TaskSpec: &task.Spec,
},
}},
expected: true,
expected: map[string]bool{
"mytask8": true,
},
}, {
name: "task-failed-pipeline-stopping",
taskName: "mytask7",
name: "task-failed-pipeline-stopping",
state: PipelineRunState{{
PipelineTask: &pts[0],
TaskRunName: "pipelinerun-mytask1",
Expand All @@ -777,10 +789,11 @@ func TestIsSkipped(t *testing.T) {
TaskSpec: &task.Spec,
},
}},
expected: true,
expected: map[string]bool{
"mytask7": true,
},
}, {
name: "tasks-when-expressions-passed",
taskName: "mytask10",
name: "tasks-when-expressions-passed",
state: PipelineRunState{{
PipelineTask: &pts[9],
TaskRunName: "pipelinerun-guardedtask",
Expand All @@ -789,10 +802,11 @@ func TestIsSkipped(t *testing.T) {
TaskSpec: &task.Spec,
},
}},
expected: false,
expected: map[string]bool{
"mytask10": false,
},
}, {
name: "tasks-when-expression-failed",
taskName: "mytask11",
name: "tasks-when-expression-failed",
state: PipelineRunState{{
PipelineTask: &pts[10],
TaskRunName: "pipelinerun-guardedtask",
Expand All @@ -801,10 +815,11 @@ func TestIsSkipped(t *testing.T) {
TaskSpec: &task.Spec,
},
}},
expected: true,
expected: map[string]bool{
"mytask11": true,
},
}, {
name: "when-expression-task-but-without-parent-done",
taskName: "mytask12",
name: "when-expression-task-but-without-parent-done",
state: PipelineRunState{{
PipelineTask: &pts[0],
TaskRun: nil,
Expand All @@ -818,7 +833,9 @@ func TestIsSkipped(t *testing.T) {
TaskSpec: &task.Spec,
},
}},
expected: false,
expected: map[string]bool{
"mytask12": false,
},
}}

for _, tc := range tcs {
Expand All @@ -828,18 +845,19 @@ func TestIsSkipped(t *testing.T) {
t.Fatalf("Could not get a dag from the TC state %#v: %v", tc.state, err)
}
stateMap := tc.state.ToMap()
rprt := stateMap[tc.taskName]
if rprt == nil {
t.Fatalf("Could not get task %s from the state: %v", tc.taskName, tc.state)
}
facts := PipelineRunFacts{
State: tc.state,
TasksGraph: d,
FinalTasksGraph: &dag.Graph{},
}
isSkipped := rprt.Skip(&facts)
if d := cmp.Diff(isSkipped, tc.expected); d != "" {
t.Errorf("Didn't get expected isSkipped %s", diff.PrintWantGot(d))
for taskName, isSkipped := range tc.expected {
rprt := stateMap[taskName]
if rprt == nil {
t.Fatalf("Could not get task %s from the state: %v", taskName, tc.state)
}
if d := cmp.Diff(isSkipped, rprt.Skip(&facts)); d != "" {
t.Errorf("Didn't get expected isSkipped %s", diff.PrintWantGot(d))
}
}
})
}
Expand Down