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 IsFinallySkipped Tests #3729

Merged
merged 1 commit into from
Jan 29, 2021
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
25 changes: 18 additions & 7 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2246,14 +2246,24 @@ func TestResolvedPipelineRunTask_IsFinallySkipped(t *testing.T) {
},
}}

expected := map[string]bool{
"final-task-1": false,
"final-task-2": true,
}

tasks := v1beta1.PipelineTaskList([]v1beta1.PipelineTask{*state[0].PipelineTask})
d, err := dag.Build(tasks, tasks.Deps())
if err != nil {
t.Fatalf("Could not get a dag from the dag tasks %#v: %v", state[0], err)
}

// build graph with finally tasks
pts := []v1beta1.PipelineTask{*state[1].PipelineTask, *state[2].PipelineTask}
var pts []v1beta1.PipelineTask
for i := range state {
if i > 0 { // first one is a dag task that produces a result
pts = append(pts, *state[i].PipelineTask)
}
}
dfinally, err := dag.Build(v1beta1.PipelineTaskList(pts), map[string][]string{})
if err != nil {
t.Fatalf("Could not get a dag from the finally tasks %#v: %v", pts, err)
Expand All @@ -2265,11 +2275,12 @@ func TestResolvedPipelineRunTask_IsFinallySkipped(t *testing.T) {
FinalTasksGraph: dfinally,
}

if state[1].IsFinallySkipped(facts) {
t.Fatalf("Didn't expect the finally task with a valid result reference to be skipped but it was skipped.")
}

if !state[2].IsFinallySkipped(facts) {
t.Fatal("Expected the finally task with an invalid result reference to be skipped but it was not skipped.")
for i := range state {
if i > 0 { // first one is a dag task that produces a result
finallyTaskName := state[i].PipelineTask.Name
if d := cmp.Diff(expected[finallyTaskName], state[i].IsFinallySkipped(facts)); d != "" {
t.Fatalf("Didn't get expected isFinallySkipped from finally task %s: %s", finallyTaskName, diff.PrintWantGot(d))
}
}
}
}