diff --git a/pkg/reconciler/pipelinerun/cancel_test.go b/pkg/reconciler/pipelinerun/cancel_test.go index 916e005e84f..764adf72285 100644 --- a/pkg/reconciler/pipelinerun/cancel_test.go +++ b/pkg/reconciler/pipelinerun/cancel_test.go @@ -20,7 +20,6 @@ import ( "context" "testing" - tb "github.com/tektoncd/pipeline/internal/builder/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" "github.com/tektoncd/pipeline/test" @@ -43,30 +42,39 @@ func TestCancelPipelineRun(t *testing.T) { }, }, }, { - name: "1-taskrun", - pipelineRun: tb.PipelineRun("test-pipeline-run-cancelled", tb.PipelineRunNamespace("foo"), - tb.PipelineRunSpec("test-pipeline", - tb.PipelineRunCancelled, - ), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("t1", &v1beta1.PipelineRunTaskRunStatus{ - PipelineTaskName: "task-1", - })), - ), - taskRuns: []*v1beta1.TaskRun{tb.TaskRun("t1", tb.TaskRunNamespace("foo"))}, + name: "one-taskrun", + pipelineRun: &v1beta1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{Name: "test-pipeline-run-cancelled"}, + Spec: v1beta1.PipelineRunSpec{ + Status: v1beta1.PipelineRunSpecStatusCancelled, + }, + Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ + "t1": {PipelineTaskName: "task-1"}, + }, + }}, + }, + taskRuns: []*v1beta1.TaskRun{ + {ObjectMeta: metav1.ObjectMeta{Name: "t1"}}, + }, }, { name: "multiple-taskruns", - pipelineRun: tb.PipelineRun("test-pipeline-run-cancelled", tb.PipelineRunNamespace("foo"), - tb.PipelineRunSpec("test-pipeline", - tb.PipelineRunCancelled, - ), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus( - "t1", &v1beta1.PipelineRunTaskRunStatus{PipelineTaskName: "task-1"}), - tb.PipelineRunTaskRunsStatus( - "t2", &v1beta1.PipelineRunTaskRunStatus{PipelineTaskName: "task-2"})), - ), - taskRuns: []*v1beta1.TaskRun{tb.TaskRun("t1", tb.TaskRunNamespace("foo")), tb.TaskRun("t2", tb.TaskRunNamespace("foo"))}, + pipelineRun: &v1beta1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{Name: "test-pipeline-run-cancelled"}, + Spec: v1beta1.PipelineRunSpec{ + Status: v1beta1.PipelineRunSpecStatusCancelled, + }, + Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ + "t1": {PipelineTaskName: "task-1"}, + "t2": {PipelineTaskName: "task-2"}, + }, + }}, + }, + taskRuns: []*v1beta1.TaskRun{ + {ObjectMeta: metav1.ObjectMeta{Name: "t1"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "t2"}}, + }, }} for _, tc := range testCases { tc := tc @@ -79,8 +87,7 @@ func TestCancelPipelineRun(t *testing.T) { ctx, cancel := context.WithCancel(ctx) defer cancel() c, _ := test.SeedTestData(t, ctx, d) - err := cancelPipelineRun(logtesting.TestLogger(t), tc.pipelineRun, c.Pipeline) - if err != nil { + if err := cancelPipelineRun(logtesting.TestLogger(t), tc.pipelineRun, c.Pipeline); err != nil { t.Fatal(err) } // This PipelineRun should still be complete and false, and the status should reflect that @@ -88,7 +95,7 @@ func TestCancelPipelineRun(t *testing.T) { if cond.IsTrue() { t.Errorf("Expected PipelineRun status to be complete and false, but was %v", cond) } - l, err := c.Pipeline.TektonV1beta1().TaskRuns("foo").List(metav1.ListOptions{}) + l, err := c.Pipeline.TektonV1beta1().TaskRuns("").List(metav1.ListOptions{}) if err != nil { t.Fatal(err) }