Skip to content

Commit

Permalink
Refactor SequentialTasks & SequentialRuns Tests
Browse files Browse the repository at this point in the history
This commit refactors the tests: TestDAGExecutionQueueSequentialTasks and TestDAGExecutionQueueSequentialRuns to reduce the scope of the variables to individual test cases so that the test cases no longer influence each other.
  • Loading branch information
EmmaMunley committed May 11, 2023
1 parent a4c80dc commit b856727
Showing 1 changed file with 38 additions and 44 deletions.
82 changes: 38 additions & 44 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,28 +1002,6 @@ func TestDAGExecutionQueue(t *testing.T) {
// TestDAGExecutionQueueSequentialTasks tests the DAGExecutionQueue function for sequential TaskRuns
// in different states for a running or stopping PipelineRun.
func TestDAGExecutionQueueSequentialTasks(t *testing.T) {
firstTask := ResolvedPipelineTask{
PipelineTask: &v1beta1.PipelineTask{
Name: "task-1",
TaskRef: &v1beta1.TaskRef{Name: "task"},
},
TaskRunName: "task-1",
ResolvedTask: &resources.ResolvedTask{
TaskSpec: &task.Spec,
},
}
secondTask := ResolvedPipelineTask{
PipelineTask: &v1beta1.PipelineTask{
Name: "task-2",
TaskRef: &v1beta1.TaskRef{Name: "task"},
RunAfter: []string{"task-1"},
},
TaskRunName: "task-2",
ResolvedTask: &resources.ResolvedTask{
TaskSpec: &task.Spec,
},
}

tcs := []struct {
name string
firstTaskRun *v1beta1.TaskRun
Expand Down Expand Up @@ -1059,10 +1037,29 @@ func TestDAGExecutionQueueSequentialTasks(t *testing.T) {
}}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
firstTask := ResolvedPipelineTask{
PipelineTask: &v1beta1.PipelineTask{
Name: "task-1",
TaskRef: &v1beta1.TaskRef{Name: "task"},
},
TaskRunName: "task-1",
ResolvedTask: &resources.ResolvedTask{
TaskSpec: &task.Spec,
},
}
secondTask := ResolvedPipelineTask{
PipelineTask: &v1beta1.PipelineTask{
Name: "task-2",
TaskRef: &v1beta1.TaskRef{Name: "task"},
RunAfter: []string{"task-1"},
},
TaskRunName: "task-2",
ResolvedTask: &resources.ResolvedTask{
TaskSpec: &task.Spec,
},
}
firstTask.TaskRun = tc.firstTaskRun
defer func() { firstTask.TaskRun = nil }()
secondTask.TaskRun = tc.secondTaskRun
defer func() { secondTask.TaskRun = nil }()
state := PipelineRunState{&firstTask, &secondTask}
d, err := dagFromState(state)
if err != nil {
Expand Down Expand Up @@ -1098,24 +1095,6 @@ func TestDAGExecutionQueueSequentialTasks(t *testing.T) {
// TestDAGExecutionQueueSequentialRuns tests the DAGExecutionQueue function for sequential Runs
// in different states for a running or stopping PipelineRun.
func TestDAGExecutionQueueSequentialRuns(t *testing.T) {
firstRun := ResolvedPipelineTask{
PipelineTask: &v1beta1.PipelineTask{
Name: "task-1",
TaskRef: &v1beta1.TaskRef{Name: "task"},
},
RunObjectName: "task-1",
CustomTask: true,
}
secondRun := ResolvedPipelineTask{
PipelineTask: &v1beta1.PipelineTask{
Name: "task-2",
TaskRef: &v1beta1.TaskRef{Name: "task"},
RunAfter: []string{"task-1"},
},
RunObjectName: "task-2",
CustomTask: true,
}

tcs := []struct {
name string
firstRun *v1beta1.CustomRun
Expand Down Expand Up @@ -1151,14 +1130,29 @@ func TestDAGExecutionQueueSequentialRuns(t *testing.T) {
}}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
firstRun := ResolvedPipelineTask{
PipelineTask: &v1beta1.PipelineTask{
Name: "task-1",
TaskRef: &v1beta1.TaskRef{Name: "task"},
},
RunObjectName: "task-1",
CustomTask: true,
}
secondRun := ResolvedPipelineTask{
PipelineTask: &v1beta1.PipelineTask{
Name: "task-2",
TaskRef: &v1beta1.TaskRef{Name: "task"},
RunAfter: []string{"task-1"},
},
RunObjectName: "task-2",
CustomTask: true,
}
if tc.firstRun != nil {
firstRun.RunObject = tc.firstRun
}
defer func() { firstRun.RunObject = nil }()
if tc.secondRun != nil {
secondRun.RunObject = tc.secondRun
}
defer func() { secondRun.RunObject = nil }()
state := PipelineRunState{&firstRun, &secondRun}
d, err := dagFromState(state)
if err != nil {
Expand Down

0 comments on commit b856727

Please sign in to comment.