Skip to content

Commit

Permalink
Remove test builders from pipelinerun cancel_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh committed Sep 19, 2020
1 parent 055e3ec commit 0d34cf9
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions pkg/reconciler/pipelinerun/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -79,16 +87,15 @@ 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
cond := tc.pipelineRun.Status.GetCondition(apis.ConditionSucceeded)
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)
}
Expand Down

0 comments on commit 0d34cf9

Please sign in to comment.