From 8575a3f65372e573c2e8f7d48c54ebdb2b780f86 Mon Sep 17 00:00:00 2001 From: pratap0007 Date: Fri, 15 Oct 2021 14:35:08 +0530 Subject: [PATCH] Replace test builders to structs in unit test for `tkn pipelinerun` Signed-off-by: Shiv Verma --- pkg/cmd/pipelinerun/cancel_test.go | 248 +++- pkg/cmd/pipelinerun/delete_test.go | 197 ++-- pkg/cmd/pipelinerun/describe_test.go | 1161 ++++++++++++------- pkg/cmd/pipelinerun/list_test.go | 149 ++- pkg/cmd/pipelinerun/logs_test.go | 1551 +++++++++++++++++--------- pkg/pipelinerun/pipelinerun_test.go | 143 ++- pkg/pipelinerun/tracker_test.go | 123 +- 7 files changed, 2349 insertions(+), 1223 deletions(-) diff --git a/pkg/cmd/pipelinerun/cancel_test.go b/pkg/cmd/pipelinerun/cancel_test.go index f8140d385..203c7a9ab 100644 --- a/pkg/cmd/pipelinerun/cancel_test.go +++ b/pkg/cmd/pipelinerun/cancel_test.go @@ -18,7 +18,6 @@ import ( "errors" "testing" - tb "github.com/tektoncd/cli/internal/builder/v1alpha1" "github.com/tektoncd/cli/pkg/test" tu "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" @@ -181,17 +180,49 @@ func Test_cancel_pipelinerun_client_err(t *testing.T) { errStr := "test generated error" prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipelineName"), - tb.PipelineRunSpec("pipelineName", - tb.PipelineRunServiceAccountName("test-sa"), - tb.PipelineRunResourceBinding("git-repo", tb.PipelineResourceBindingRef("some-repo")), - tb.PipelineRunResourceBinding("build-image", tb.PipelineResourceBindingRef("some-image")), - tb.PipelineRunParam("pipeline-param-1", "somethingmorefun"), - tb.PipelineRunParam("rev-param", "revision1"), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: "pipelineName", + }, + ServiceAccountName: "test-sa", + Resources: []v1beta1.PipelineResourceBinding{ + { + Name: "git-repo", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "some-repo", + }, + }, + { + Name: "build-image", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "some-image", + }, + }, + }, + Params: []v1beta1.Param{ + { + Name: "pipeline-param-1", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "somethingmorefun", + }, + }, + { + Name: "rev-param", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "revision1", + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) @@ -231,20 +262,56 @@ func Test_finished_pipelinerun_success(t *testing.T) { prName := "test-pipeline-run-123" prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipelineName"), - tb.PipelineRunSpec("pipelineName", - tb.PipelineRunServiceAccountName("test-sa"), - tb.PipelineRunResourceBinding("git-repo", tb.PipelineResourceBindingRef("some-repo")), - tb.PipelineRunResourceBinding("build-image", tb.PipelineResourceBindingRef("some-image")), - tb.PipelineRunParam("pipeline-param-1", "somethingmorefun"), - tb.PipelineRunParam("rev-param", "revision1"), - ), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(success), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: "pipelineName", + }, + ServiceAccountName: "test-sa", + Resources: []v1beta1.PipelineResourceBinding{ + { + Name: "git-repo", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "some-repo", + }, + }, + { + Name: "build-image", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "some-image", + }, + }, + }, + Params: []v1beta1.Param{ + { + Name: "pipeline-param-1", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "somethingmorefun", + }, + }, + { + Name: "rev-param", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "revision1", + }, + }, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + success, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) @@ -277,20 +344,57 @@ func Test_finished_pipelinerun_failure(t *testing.T) { prName := "test-pipeline-run-123" prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipelineName"), - tb.PipelineRunSpec("pipelineName", - tb.PipelineRunServiceAccountName("test-sa"), - tb.PipelineRunResourceBinding("git-repo", tb.PipelineResourceBindingRef("some-repo")), - tb.PipelineRunResourceBinding("build-image", tb.PipelineResourceBindingRef("some-image")), - tb.PipelineRunParam("pipeline-param-1", "somethingmorefun"), - tb.PipelineRunParam("rev-param", "revision1"), - ), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(failure), - ), - ), + + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: "pipelineName", + }, + ServiceAccountName: "test-sa", + Resources: []v1beta1.PipelineResourceBinding{ + { + Name: "git-repo", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "some-repo", + }, + }, + { + Name: "build-image", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "some-image", + }, + }, + }, + Params: []v1beta1.Param{ + { + Name: "pipeline-param-1", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "somethingmorefun", + }, + }, + { + Name: "rev-param", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "revision1", + }, + }, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + failure, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) @@ -323,20 +427,56 @@ func Test_finished_pipelinerun_cancel(t *testing.T) { prName := "test-pipeline-run-123" prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipelineName"), - tb.PipelineRunSpec("pipelineName", - tb.PipelineRunServiceAccountName("test-sa"), - tb.PipelineRunResourceBinding("git-repo", tb.PipelineResourceBindingRef("some-repo")), - tb.PipelineRunResourceBinding("build-image", tb.PipelineResourceBindingRef("some-image")), - tb.PipelineRunParam("pipeline-param-1", "somethingmorefun"), - tb.PipelineRunParam("rev-param", "revision1"), - ), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(cancel), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipelineName"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: "pipelineName", + }, + ServiceAccountName: "test-sa", + Resources: []v1beta1.PipelineResourceBinding{ + { + Name: "git-repo", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "some-repo", + }, + }, + { + Name: "build-image", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "some-image", + }, + }, + }, + Params: []v1beta1.Param{ + { + Name: "pipeline-param-1", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "somethingmorefun", + }, + }, + { + Name: "rev-param", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "revision1", + }, + }, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + cancel, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Namespaces: ns}) diff --git a/pkg/cmd/pipelinerun/delete_test.go b/pkg/cmd/pipelinerun/delete_test.go index c21ba3d30..504c7c3fc 100644 --- a/pkg/cmd/pipelinerun/delete_test.go +++ b/pkg/cmd/pipelinerun/delete_test.go @@ -21,7 +21,6 @@ import ( "time" "github.com/jonboulle/clockwork" - tb "github.com/tektoncd/cli/internal/builder/v1alpha1" "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" @@ -32,7 +31,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/dynamic" - "knative.dev/pkg/apis" duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) @@ -49,80 +47,133 @@ func TestPipelineRunDelete(t *testing.T) { } pdata := []*v1alpha1.Pipeline{ - tb.Pipeline("pipeline", - tb.PipelineNamespace("ns"), - // created 5 minutes back - cb.PipelineCreationTimestamp(clock.Now().Add(-5*time.Minute)), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline", + Namespace: "ns", + // created 5 minutes back + CreationTimestamp: metav1.Time{Time: clock.Now().Add(-5 * time.Minute)}, + }, + }, } prdata := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run-1", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunLabel("iam", "tobedeleted"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - // pipeline run starts now - tb.PipelineRunStartTime(clock.Now()), - // takes 10 minutes to complete - cb.PipelineRunCompletionTime(clock.Now().Add(10*time.Minute)), - ), - ), - tb.PipelineRun("pipeline-run-2", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunLabel("iam", "tobedeleted"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - // pipeline run starts now - tb.PipelineRunStartTime(clock.Now()), - // takes 10 minutes to complete - cb.PipelineRunCompletionTime(clock.Now().Add(10*time.Minute)), - ), - ), - tb.PipelineRun("pipeline-run-3", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - // pipeline run starts now - tb.PipelineRunStartTime(clock.Now()), - // takes 10 minutes to complete - cb.PipelineRunCompletionTime(clock.Now().Add(10*time.Minute)), - ), - ), - tb.PipelineRun("pipeline-run-realnow", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - // pipeline run starts now - tb.PipelineRunStartTime(time.Now()), - // takes 10 minutes to complete - cb.PipelineRunCompletionTime(time.Now().Add(60*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run-1", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline", "iam": "tobedeleted"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + // pipeline run starts now + StartTime: &metav1.Time{Time: clock.Now()}, + // takes 10 minutes to complete + CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run-2", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline", "iam": "tobedeleted"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + // pipeline run starts now + StartTime: &metav1.Time{Time: clock.Now()}, + // takes 10 minutes to complete + CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run-3", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + // pipeline run starts now + StartTime: &metav1.Time{Time: clock.Now()}, + // takes 10 minutes to complete + CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run-realnow", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + // pipeline run starts now + StartTime: &metav1.Time{Time: time.Now()}, + // takes 60 minutes to complete + CompletionTime: &metav1.Time{Time: time.Now().Add(60 * time.Minute)}, + }, + }, + }, } type clients struct { diff --git a/pkg/cmd/pipelinerun/describe_test.go b/pkg/cmd/pipelinerun/describe_test.go index 351a33308..32f700c6b 100644 --- a/pkg/cmd/pipelinerun/describe_test.go +++ b/pkg/cmd/pipelinerun/describe_test.go @@ -21,7 +21,6 @@ import ( "time" "github.com/jonboulle/clockwork" - tb "github.com/tektoncd/cli/internal/builder/v1alpha1" "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" @@ -89,38 +88,60 @@ func TestPipelineRunDescribe_only_taskrun(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -159,53 +180,81 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), - tb.TaskRun("tr-2", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(5*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(9*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-2", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(9 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunTaskRunsStatus("tr-2", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-2", - Status: &trs[1].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(15*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + "tr-2": {PipelineTaskName: "t-2", Status: &trs[1].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(15 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -246,41 +295,61 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-0", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-0", - }), - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionFalse, - Reason: v1beta1.PipelineRunReasonFailed.String(), - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-0": {PipelineTaskName: "t-0"}, + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1beta1.PipelineRunReasonFailed.String(), + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -319,42 +388,63 @@ func TestPipelineRunDescribe_failed(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - tb.StatusCondition(apis.Condition{ - Status: corev1.ConditionFalse, - Reason: v1beta1.PipelineRunReasonFailed.String(), - Message: "Testing tr failed", - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1beta1.PipelineRunReasonFailed.String(), + Message: "Testing tr failed", + }, + }, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline", - tb.PipelineRunServiceAccountName("test-sa"), - ), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionFalse, - Reason: "Resource not found", - Message: "Resource test-resource not found in the pipelinerun", - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + ServiceAccountName: "test-sa", + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: "Resource not found", + Message: "Resource test-resource not found in the pipelinerun", + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -423,37 +513,54 @@ func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline", - tb.PipelineRunServiceAccountName("test-sa"), - ), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionFalse, - Reason: "Resource not found", - Message: "Resource test-resource not found in the pipelinerun", - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + ServiceAccountName: "test-sa", + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: "Resource not found", + Message: "Resource test-resource not found in the pipelinerun", + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -492,32 +599,45 @@ func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline", - tb.PipelineRunServiceAccountName("test-sa"), - ), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + ServiceAccountName: "test-sa", + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -556,44 +676,78 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline", - tb.PipelineRunServiceAccountName("test-sa"), - tb.PipelineRunParam("test-param", "param-value"), - tb.PipelineRunResourceBinding("test-resource", - tb.PipelineResourceBindingRef("test-resource-ref"), - ), - ), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + ServiceAccountName: "test-sa", + Resources: []v1alpha1.PipelineResourceBinding{ + { + Name: "test-resource", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "test-resource-ref", + }, + }, + }, + Params: []v1alpha1.Param{ + { + Name: "test-param", + Value: v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "param-value", + }, + }, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -632,13 +786,20 @@ func TestPipelineRunDescribe_without_start_time(t *testing.T) { clock := clockwork.NewFakeClock() pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus(), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -674,12 +835,14 @@ func TestPipelineRunDescribe_without_pipelineref(t *testing.T) { clock := clockwork.NewFakeClock() pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunStatus(), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + }, } namespaces := []*corev1.Namespace{ @@ -715,12 +878,14 @@ func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T clock := clockwork.NewFakeClock() pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunStatus(), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + }, } namespaces := []*corev1.Namespace{ @@ -756,42 +921,75 @@ func TestPipelineRunDescribe_no_resourceref(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline", - tb.PipelineRunServiceAccountName("test-sa"), - tb.PipelineRunParam("test-param", "param-value"), - tb.PipelineRunResourceBinding("test-resource"), - ), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + ServiceAccountName: "test-sa", + Resources: []v1alpha1.PipelineResourceBinding{ + { + Name: "test-resource", + }, + }, + Params: []v1alpha1.Param{ + { + Name: "test-param", + Value: v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "param-value", + }, + }, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -830,39 +1028,61 @@ func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionFalse, - Reason: "PipelineRunCancelled", - Message: "PipelineRun \"pipeline-run\" was cancelled", - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: "PipelineRunCancelled", + Message: "PipelineRun \"pipeline-run\" was cancelled", + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -901,35 +1121,55 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionReady, - Status: corev1.ConditionUnknown, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Type: apis.ConditionReady, + }, + }, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionUnknown, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }), - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunStartTime(clock.Now()), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Reason: v1beta1.PipelineRunReasonRunning.String(), + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -966,10 +1206,20 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { func TestPipelineRunDescribe_custom_timeout(t *testing.T) { prun := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pr-custom-timeout", - tb.PipelineRunNamespace("ns"), - tb.PipelineRunSpec("pr-custom-timeout", tb.PipelineRunTimeout(time.Minute)), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr-custom-timeout", + Namespace: "ns", + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pr-custom-timeout", + }, + Timeout: &metav1.Duration{ + Duration: time.Minute, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -1005,9 +1255,12 @@ func TestPipelineRunsDescribe_custom_output(t *testing.T) { expected := "pipelinerun.tekton.dev/" + pipelinerunname prun := []*v1alpha1.PipelineRun{ - tb.PipelineRun(pipelinerunname, - tb.PipelineRunNamespace("ns"), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + }, } namespaces := []*corev1.Namespace{ { @@ -1610,86 +1863,142 @@ func TestPipelineRunDescribe_last(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1alpha1.TaskRun{ - tb.TaskRun("tr-1", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), - tb.TaskRun("tr-2", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(5*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(9*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), - tb.TaskRun("tr-3", - tb.TaskRunNamespace("ns"), - tb.TaskRunStatus( - tb.TaskRunStartTime(clock.Now().Add(5*time.Minute)), - cb.TaskRunCompletionTime(clock.Now().Add(9*time.Minute)), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-2", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(9 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-3", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(9 * time.Minute)}, + }, + }, + }, } pipelineRuns := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now()), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunTaskRunsStatus("tr-2", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-2", - Status: &trs[1].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(clock.Now().Add(5*time.Minute)), - cb.PipelineRunCompletionTime(clock.Now().Add(20*time.Minute)), - ), - ), - tb.PipelineRun("pipeline-run2", - tb.PipelineRunNamespace("ns"), - cb.PipelineRunCreationTimestamp(clock.Now().Add(5*time.Minute)), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-1", - Status: &trs[0].Status, - }), - tb.PipelineRunTaskRunsStatus("tr-3", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "t-3", - Status: &trs[1].Status, - }), - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(clock.Now()), - cb.PipelineRunCompletionTime(clock.Now().Add(15*time.Minute)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + Timeout: &metav1.Duration{Duration: 1 * time.Hour}, + PipelineRef: &v1beta1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ + "tr-1": { + PipelineTaskName: "t-1", + Status: &trs[0].Status, + }, + "tr-2": { + PipelineTaskName: "t-2", + Status: &trs[1].Status, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run2", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(15 * time.Minute)}, + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ + "tr-1": { + PipelineTaskName: "t-1", + Status: &trs[0].Status, + }, + "tr-3": { + PipelineTaskName: "t-3", + Status: &trs[1].Status, + }, + }, + }, + }, + }, } namespaces := []*corev1.Namespace{ @@ -1853,10 +2162,20 @@ func TestPipelineRunDescribe_v1beta1_with_results(t *testing.T) { func TestPipelineRunDescribe_zero_timeout(t *testing.T) { prun := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipeline-run-zero-timeout", - tb.PipelineRunNamespace("ns"), - tb.PipelineRunSpec("pipeline-zero-timeout", tb.PipelineRunTimeout(0)), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run-zero-timeout", + Namespace: "ns", + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: "pipeline-zero-timeout", + }, + Timeout: &metav1.Duration{ + Duration: 0, + }, + }, + }, } namespaces := []*corev1.Namespace{ diff --git a/pkg/cmd/pipelinerun/list_test.go b/pkg/cmd/pipelinerun/list_test.go index 2af91c476..f26e61204 100644 --- a/pkg/cmd/pipelinerun/list_test.go +++ b/pkg/cmd/pipelinerun/list_test.go @@ -22,7 +22,6 @@ import ( "github.com/jonboulle/clockwork" "github.com/spf13/cobra" - tb "github.com/tektoncd/cli/internal/builder/v1alpha1" "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" @@ -34,7 +33,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/dynamic" - "knative.dev/pkg/apis" duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) @@ -48,66 +46,99 @@ func TestListPipelineRuns(t *testing.T) { pr3Started := clock.Now().Add(-1 * time.Hour) prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pr0-1", - tb.PipelineRunNamespace("namespace"), - tb.PipelineRunLabel("tekton.dev/pipeline", "random"), - tb.PipelineRunStatus(), - ), - tb.PipelineRun("pr1-1", - tb.PipelineRunNamespace("namespace"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(pr1Started), - cb.PipelineRunCompletionTime(pr1Started.Add(runDuration)), - ), - ), - tb.PipelineRun("pr2-1", - tb.PipelineRunNamespace("namespace"), - tb.PipelineRunLabel("tekton.dev/pipeline", "random"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }), - tb.PipelineRunStartTime(pr2Started), - ), - ), - tb.PipelineRun("pr2-2", - tb.PipelineRunNamespace("namespace"), - tb.PipelineRunLabel("tekton.dev/pipeline", "random"), - tb.PipelineRunLabel("viva", "galapagos"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionFalse, - Reason: v1beta1.PipelineRunReasonFailed.String(), - }), - tb.PipelineRunStartTime(pr3Started), - cb.PipelineRunCompletionTime(pr3Started.Add(runDuration)), - ), - ), - tb.PipelineRun("pr3-1", - tb.PipelineRunNamespace("namespace"), - tb.PipelineRunLabel("tekton.dev/pipeline", "random"), - tb.PipelineRunLabel("viva", "wakanda"), - tb.PipelineRunStatus(), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr0-1", + Namespace: "namespace", + Labels: map[string]string{"tekton.dev/pipeline": "random"}, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr1-1", + Namespace: "namespace", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr1Started}, + CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr2-1", + Namespace: "namespace", + Labels: map[string]string{"tekton.dev/pipeline": "random"}, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonRunning.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr2Started}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr2-2", + Namespace: "namespace", + Labels: map[string]string{"tekton.dev/pipeline": "random", "viva": "galapagos"}, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1beta1.PipelineRunReasonFailed.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr3Started}, + CompletionTime: &metav1.Time{Time: pr3Started.Add(runDuration)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr3-1", + Namespace: "namespace", + Labels: map[string]string{"tekton.dev/pipeline": "random", "viva": "wakanda"}, + }, + }, } prsMultipleNs := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pr4-1", - tb.PipelineRunNamespace("namespace-tout"), - tb.PipelineRunLabel("tekton.dev/pipeline", "random"), - tb.PipelineRunStatus(), - ), - tb.PipelineRun("pr4-2", - tb.PipelineRunNamespace("namespace-lacher"), - tb.PipelineRunLabel("tekton.dev/pipeline", "random"), - tb.PipelineRunStatus(), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr4-1", + Namespace: "namespace-tout", + Labels: map[string]string{"tekton.dev/pipeline": "random"}, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr4-2", + Namespace: "namespace-lacher", + Labels: map[string]string{"tekton.dev/pipeline": "random"}, + }, + }, } ns := []*corev1.Namespace{ diff --git a/pkg/cmd/pipelinerun/logs_test.go b/pkg/cmd/pipelinerun/logs_test.go index 5e1a6b328..9c63ded9f 100644 --- a/pkg/cmd/pipelinerun/logs_test.go +++ b/pkg/cmd/pipelinerun/logs_test.go @@ -21,8 +21,6 @@ import ( "time" "github.com/jonboulle/clockwork" - tb "github.com/tektoncd/cli/internal/builder/v1alpha1" - tbv1beta1 "github.com/tektoncd/cli/internal/builder/v1beta1" "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/options" "github.com/tektoncd/cli/pkg/pods/fake" @@ -119,23 +117,38 @@ func TestLog_no_pipelinerun_argument(t *testing.T) { func TestLog_run_found(t *testing.T) { clock := clockwork.NewFakeClock() pdata := []*v1alpha1.Pipeline{ - tb.Pipeline("pipeline", - tb.PipelineNamespace("ns"), - cb.PipelineCreationTimestamp(clock.Now().Add(-15*time.Minute)), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now().Add(-15 * time.Minute)}, + }, + }, } prdata := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipelinerun-1", - tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun1", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{ Pipelines: pdata, @@ -169,16 +182,23 @@ func TestLog_run_found(t *testing.T) { func TestLog_run_not_found(t *testing.T) { pr := []*v1alpha1.PipelineRun{ - tb.PipelineRun("output-pipeline-1", - tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "output-pipeline-1"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionFalse, - Reason: v1beta1.PipelineRunReasonFailed.String(), - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "output-pipeline-1", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "output-pipeline-1"}, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, } ns := []*corev1.Namespace{ @@ -239,112 +259,211 @@ func TestPipelinerunLogs(t *testing.T) { } trs := []*v1alpha1.TaskRun{ - tb.TaskRun(tr1Name, - tb.TaskRunNamespace(ns), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task1Name), - ), - tb.TaskRunStatus( - tb.PodName(tr1Pod), - tb.TaskRunStartTime(tr1StartTime), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - tb.StepState( - cb.StepName(tr1Step1Name), - tb.StateTerminated(0), - ), - tb.StepState( - cb.StepName(nopStep), - tb.StateTerminated(0), - ), - ), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task1Name), - ), - ), - tb.TaskRun(tr2Name, - tb.TaskRunNamespace(ns), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task2Name), - ), - tb.TaskRunStatus( - tb.PodName(tr2Pod), - tb.TaskRunStartTime(tr2StartTime), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - tb.StepState( - cb.StepName(tr2Step1Name), - tb.StateTerminated(0), - ), - tb.StepState( - cb.StepName(nopStep), - tb.StateTerminated(0), - ), - ), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task2Name), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: ns, + Name: tr1Name, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{ + Name: task1Name, + }, + }, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: tr1StartTime}, + PodName: tr1Pod, + Steps: []v1beta1.StepState{ + { + Name: tr1Step1Name, + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + { + Name: nopStep, + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: ns, + Name: tr2Name, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{ + Name: task2Name, + }, + }, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: tr2StartTime}, + PodName: tr2Pod, + Steps: []v1beta1.StepState{ + { + Name: tr2Step1Name, + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + { + Name: nopStep, + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + }, + }, + }, + }, } prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunTaskRunsStatus(tr1Name, &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: task1Name, - Status: &trs[0].Status, - }), - tb.PipelineRunTaskRunsStatus(tr2Name, &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: task2Name, - Status: &trs[1].Status, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + tr1Name: {PipelineTaskName: task1Name, Status: &trs[0].Status}, + tr2Name: {PipelineTaskName: task2Name, Status: &trs[1].Status}, + }, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, } pps := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(task1Name, task1Name), - tb.PipelineTask(task2Name, task2Name), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: task1Name, + TaskRef: &v1alpha1.TaskRef{ + Name: task1Name, + }, + }, + { + Name: task2Name, + TaskRef: &v1alpha1.TaskRef{ + Name: task2Name, + }, + }, + }, + }, + }, } p := []*corev1.Pod{ - tbv1beta1.Pod(tr1Pod, - tbv1beta1.PodNamespace(ns), - tbv1beta1.PodLabel("tekton.dev/task", pipelineName), - tbv1beta1.PodSpec( - tbv1beta1.PodInitContainer(tr1InitStep1, "override-with-creds:latest"), - tbv1beta1.PodInitContainer(tr1InitStep2, "override-with-tools:latest"), - tbv1beta1.PodContainer(tr1Step1Name, tr1Step1Name+":latest"), - tbv1beta1.PodContainer(nopStep, "override-with-nop:latest"), - ), - cb.PodStatus( - cb.PodInitContainerStatus(tr1InitStep1, "override-with-creds:latest"), - cb.PodInitContainerStatus(tr1InitStep2, "override-with-tools:latest"), - ), - ), - tbv1beta1.Pod(tr2Pod, - tbv1beta1.PodNamespace(ns), - tbv1beta1.PodLabel("tekton.dev/task", pipelineName), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer(tr2Step1Name, tr1Step1Name+":latest"), - tbv1beta1.PodContainer(nopStep, "override-with-nop:latest"), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr1Pod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + InitContainers: []corev1.Container{ + { + Name: tr1InitStep1, + Image: "override-with-creds:latest", + }, + { + Name: tr1InitStep2, + Image: "override-with-tools:latest", + }, + }, + Containers: []corev1.Container{ + { + Name: tr1Step1Name, + Image: tr1Step1Name + ":latest", + }, + { + Name: nopStep, + Image: "override-with-nop:latest", + }, + }, + }, + Status: corev1.PodStatus{ + Phase: corev1.PodPhase(corev1.PodSucceeded), + InitContainerStatuses: []corev1.ContainerStatus{ + { + Name: tr1InitStep1, + Image: "override-with-creds:latest", + }, + { + Name: tr1InitStep2, + Image: "override-with-tools:latest", + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr2Pod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: tr2Step1Name, + Image: tr1Step1Name + ":latest", + }, + { + Name: nopStep, + Image: "override-with-nop:latest", + }, + }, + }, + }, } fakeLogs := fake.Logs( @@ -460,66 +579,122 @@ func TestPipelinerunLog_completed_taskrun_only(t *testing.T) { ) trdata := []*v1alpha1.TaskRun{ - tb.TaskRun(tr1Name, - tb.TaskRunNamespace(ns), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task1Name), - ), - tb.TaskRunStatus( - tb.PodName(tr1Pod), - tb.TaskRunStartTime(tr1StartTime), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - tb.StepState( - cb.StepName(tr1Step1Name), - tb.StateTerminated(0), - ), - tb.StepState( - cb.StepName("nop"), - tb.StateTerminated(0), - ), - ), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task1Name), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: ns, + Name: tr1Name, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{ + Name: task1Name, + }, + }, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: tr1StartTime}, + PodName: tr1Pod, + Steps: []v1beta1.StepState{ + { + Name: tr1Step1Name, + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + { + Name: "nop", + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + }, + }, + }, + }, } pdata := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(task1Name, task1Name), - tb.PipelineTask(task2Name, task2Name), - tb.PipelineTask(task3Name, task3Name), - tb.PipelineTask(task4Name, task4Name), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: task1Name, + TaskRef: &v1alpha1.TaskRef{ + Name: task1Name, + }, + }, + { + Name: task2Name, + TaskRef: &v1alpha1.TaskRef{ + Name: task2Name, + }, + }, + { + Name: task3Name, + TaskRef: &v1alpha1.TaskRef{ + Name: task3Name, + }, + }, + { + Name: task4Name, + TaskRef: &v1alpha1.TaskRef{ + Name: task4Name, + }, + }, + }, + }, + }, } prdata := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunSpec(pipelineName), - - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }), - tb.PipelineRunTaskRunsStatus(tr1Name, &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: task1Name, - Status: &v1alpha1.TaskRunStatus{ - Status: duckv1beta1.Status{}, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: tr1StartTime}, - CompletionTime: &metav1.Time{Time: tr1CompletionTime}, - }, - }, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonRunning.String(), + }, + }, + }, + PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ + tr1Name: { + PipelineTaskName: task1Name, + Status: &v1beta1.TaskRunStatus{ + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: tr1StartTime}, + CompletionTime: &metav1.Time{Time: tr1CompletionTime}, + }, + }, + }, + }, + }, + }, + }, } // define pipeline in pipelineRef cs, _ := test.SeedTestData(t, pipelinetest.Data{ @@ -534,14 +709,25 @@ func TestPipelinerunLog_completed_taskrun_only(t *testing.T) { }, }, Pods: []*corev1.Pod{ - tbv1beta1.Pod(tr1Pod, - tbv1beta1.PodNamespace(ns), - tbv1beta1.PodLabel("tekton.dev/task", pipelineName), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer(tr1Step1Name, tr1Step1Name+":latest"), - tbv1beta1.PodContainer("nop", "override-with-nop:latest"), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr1Pod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: tr1Step1Name, + Image: tr1Step1Name + ":latest", + }, + { + Name: "nop", + Image: "override-with-nop:latest", + }, + }, + }, + }, }, }) cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) @@ -556,52 +742,94 @@ func TestPipelinerunLog_completed_taskrun_only(t *testing.T) { } tdata2 := []*v1alpha1.Task{ - tb.Task("output-task2", tb.TaskNamespace("ns"), cb.TaskCreationTime(clockwork.NewFakeClock().Now())), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "output-task2", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clockwork.NewFakeClock().Now()}, + }, + }, } trdata2 := []*v1alpha1.TaskRun{ - tb.TaskRun("output-taskrun2", - tb.TaskRunNamespace("ns"), - tb.TaskRunLabel("tekton.dev/task", "task"), - tb.TaskRunSpec(tb.TaskRunTaskRef("output-task2")), - tb.TaskRunStatus( - tb.PodName("output-task-pod-embedded"), - tb.TaskRunStartTime(clockwork.NewFakeClock().Now()), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.StepState( - cb.StepName("test-step"), - tb.StateTerminated(0), - ), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "output-taskrun2", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/task": "task"}, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "output-task2", + }, + }, + Status: v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Type: apis.ConditionSucceeded, + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + PodName: "output-task-pod-embedded", + StartTime: &metav1.Time{Time: clockwork.NewFakeClock().Now()}, + Steps: []v1alpha1.StepState{ + { + Name: "test-step", + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + }, + }, + }, + }, } prdata2 := []*v1alpha1.PipelineRun{ - tb.PipelineRun("embedded-pipeline-1", - tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "embedded-pipeline-1"), - tb.PipelineRunSpec("", tb.PipelineRunPipelineSpec( - tb.PipelineTask("output-task2", "output-task2"), - )), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }), - tb.PipelineRunTaskRunsStatus("output-taskrun2", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "output-task2", - Status: &v1alpha1.TaskRunStatus{ - Status: duckv1beta1.Status{}, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: tr1StartTime}, - CompletionTime: &metav1.Time{Time: tr1CompletionTime}, - }, - }, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "embedded-pipeline-1", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "embedded-pipeline-1"}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineSpec: &v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: "output-task2", + TaskRef: &v1alpha1.TaskRef{ + Name: "output-task2", + }, + }, + }, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonRunning.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + "output-taskrun2": {PipelineTaskName: "output-task2", Status: &v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{}, + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: tr1StartTime}, + CompletionTime: &metav1.Time{Time: tr1CompletionTime}, + }, + }}, + }, + }, + }, + }, } // define embedded pipeline cs2, _ := test.SeedTestData(t, pipelinetest.Data{ @@ -616,16 +844,27 @@ func TestPipelinerunLog_completed_taskrun_only(t *testing.T) { }, }, Pods: []*corev1.Pod{ - tbv1beta1.Pod("output-task-pod-embedded", - tbv1beta1.PodNamespace("ns"), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer("test-step", "test-step1:latest"), - tbv1beta1.PodContainer("nop2", "override-with-nop:latest"), - ), - cb.PodStatus( - cb.PodPhase(corev1.PodSucceeded), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "output-task-pod-embedded", + Namespace: "ns", + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "test-step", + Image: "test-step1:latest", + }, + { + Name: "nop2", + Image: "override-with-nop:latest", + }, + }, + }, + Status: corev1.PodStatus{ + Phase: corev1.PodPhase(corev1.PodSucceeded), + }, + }, }, }) cs2.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) @@ -716,72 +955,123 @@ func TestPipelinerunLog_follow_mode(t *testing.T) { } trs := []*v1alpha1.TaskRun{ - tb.TaskRun(tr1Name, - tb.TaskRunNamespace(ns), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task1Name), - ), - tb.TaskRunStatus( - tb.PodName(tr1Pod), - tb.TaskRunStartTime(tr1StartTime), - tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }), - tb.StepState( - cb.StepName(tr1Step1Name), - tb.StateTerminated(0), - ), - tb.StepState( - cb.StepName("nop"), - tb.StateTerminated(0), - ), - ), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task1Name), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr1Name, + Namespace: ns, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: task1Name, + }, + }, + Status: v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + PodName: tr1Pod, + StartTime: &metav1.Time{Time: tr1StartTime}, + Steps: []v1alpha1.StepState{ + { + Name: tr1Step1Name, + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + { + Name: "nop", + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 0, + }, + }, + }, + }, + }, + }, + }, } prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }), - tb.PipelineRunTaskRunsStatus(tr1Name, &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: task1Name, - Status: &trs[0].Status, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + tr1Name: {PipelineTaskName: task1Name, Status: &trs[0].Status}, + }, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonRunning.String(), + }, + }, + }, + }, + }, } pps := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(task1Name, task1Name), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: task1Name, + TaskRef: &v1beta1.TaskRef{ + Name: task1Name, + }, + }, + }, + }, + }, } p := []*corev1.Pod{ - tbv1beta1.Pod(tr1Pod, - tbv1beta1.PodNamespace(ns), - tbv1beta1.PodLabel("tekton.dev/task", pipelineName), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer(tr1Step1Name, tr1Step1Name+":latest"), - tbv1beta1.PodContainer("nop", "override-with-nop:latest"), - ), - cb.PodStatus( - cb.PodPhase(corev1.PodSucceeded), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr1Pod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: tr1Step1Name, + Image: tr1Step1Name + ":latest", + }, + { + Name: "nop", + Image: "override-with-nop:latest", + }, + }, + }, + Status: corev1.PodStatus{ + Phase: corev1.PodPhase(corev1.PodSucceeded), + }, + }, } fakeLogStream := fake.Logs( @@ -840,32 +1130,56 @@ func TestLogs_error_log(t *testing.T) { } ts := []*v1alpha1.Task{ - tb.Task(taskName, - tb.TaskNamespace(ns), - tb.TaskSpec()), + { + ObjectMeta: metav1.ObjectMeta{ + Name: taskName, + Namespace: ns, + }, + }, } prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionFalse, - Message: errMsg, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Message: errMsg, + }, + }, + }, + }, + }, } ps := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(taskName, taskName), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: taskName, + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: ps, Tasks: ts, Namespaces: nsList}) cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"task", "pipeline", "pipelinerun"}) @@ -903,26 +1217,47 @@ func TestLogs_nologs(t *testing.T) { } prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionUnknown, - Message: "Running", - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Message: "Running", + }, + }, + }, + }, + }, } ps := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(taskName, taskName), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: taskName, + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: ps, Namespaces: nsList}) cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) @@ -960,27 +1295,48 @@ func TestLog_run_failed_with_and_without_follow(t *testing.T) { } prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Message: failMessage, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Type: apis.ConditionSucceeded, + Message: failMessage, + }, + }, + }, + }, + }, } ps := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(taskName, taskName), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: taskName, + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: ps, Namespaces: nsList}) cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) @@ -1020,57 +1376,93 @@ func TestLog_pipelinerun_still_running(t *testing.T) { nsList := []*corev1.Namespace{ { ObjectMeta: metav1.ObjectMeta{ - Name: ns, + Name: ns, + }, + }, + } + + initialPRs := []*v1alpha1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Type: apis.ConditionSucceeded, + Message: "Running", + }, + }, + }, + }, + }, + } + + finalPRs := []*v1alpha1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Type: apis.ConditionSucceeded, + Message: "Running", + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + Message: "Completed", + }, + }, + }, }, }, } - initialPRs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Message: "Running", - }), - ), - ), - } - - finalPRs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Message: "Running", - }), - ), - ), - - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - Message: "Completed", - }), - ), - ), - } - ps := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(taskName, taskName), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: taskName, + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: initialPRs, Pipelines: ps, Namespaces: nsList}) watcher := watch.NewFake() @@ -1112,27 +1504,48 @@ func TestLog_pipelinerun_status_done(t *testing.T) { } prs := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Message: "Running", - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Type: apis.ConditionSucceeded, + Message: "Running", + }, + }, + }, + }, + }, } ps := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(taskName, taskName), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: taskName, + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: prs, Pipelines: ps, Namespaces: nsList}) cs.Pipeline.Resources = cb.APIResourceList(versionA1, []string{"pipeline", "pipelinerun"}) @@ -1188,41 +1601,77 @@ func TestLog_pipelinerun_last(t *testing.T) { } pipelines := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(taskName, taskName), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: taskName, + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + }, + }, + }, + }, } pipelineruns := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName2, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", pipelineName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStartTime(time.Now().Add(time.Second)), - tb.PipelineRunStatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Message: "Running", - }), - ), - ), - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", pipelineName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStartTime(time.Now()), - tb.PipelineRunStatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Message: "Running", - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName2, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": pipelineName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: time.Now().Add(time.Second)}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Type: apis.ConditionSucceeded, + Message: "Running", + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": pipelineName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: time.Now()}, + }, + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Type: apis.ConditionSucceeded, + Message: "Running", + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: pipelineruns, Pipelines: pipelines, Namespaces: namespaces}) @@ -1271,27 +1720,48 @@ func TestLog_pipelinerun_only_one(t *testing.T) { } pipelines := []*v1alpha1.Pipeline{ - tb.Pipeline(pipelineName, - tb.PipelineNamespace(ns), - tb.PipelineSpec( - tb.PipelineTask(taskName, taskName), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + Namespace: ns, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: taskName, + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + }, + }, + }, + }, } pipelineruns := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, - tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", pipelineName), - tb.PipelineRunSpec(pipelineName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Message: "Running", - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": pipelineName}, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: pipelineName, + }, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Type: apis.ConditionSucceeded, + Message: "Running", + }, + }, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineRuns: pipelineruns, Pipelines: pipelines, Namespaces: namespaces}) @@ -1501,14 +1971,25 @@ func TestPipelinerunLog_completed_taskrun_only_v1beta1(t *testing.T) { }, }, Pods: []*corev1.Pod{ - tbv1beta1.Pod(tr1Pod, - tbv1beta1.PodNamespace(ns), - tbv1beta1.PodLabel("tekton.dev/task", pipelineName), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer(tr1Step1Name, tr1Step1Name+":latest"), - tbv1beta1.PodContainer("nop", "override-with-nop:latest"), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr1Pod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: tr1Step1Name, + Image: tr1Step1Name + ":latest", + }, + { + Name: "nop", + Image: "override-with-nop:latest", + }, + }, + }, + }, }, }) cs.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) @@ -1632,16 +2113,27 @@ func TestPipelinerunLog_completed_taskrun_only_v1beta1(t *testing.T) { }, }, Pods: []*corev1.Pod{ - tbv1beta1.Pod("output-task-pod-embedded", - tbv1beta1.PodNamespace("ns"), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer("test-step", "test-step1:latest"), - tbv1beta1.PodContainer("nop2", "override-with-nop:latest"), - ), - cb.PodStatus( - cb.PodPhase(corev1.PodSucceeded), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "output-task-pod-embedded", + Namespace: "ns", + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "test-step", + Image: "test-step1:latest", + }, + { + Name: "nop2", + Image: "override-with-nop:latest", + }, + }, + }, + Status: corev1.PodStatus{ + Phase: corev1.PodPhase(corev1.PodSucceeded), + }, + }, }, }) cs2.Pipeline.Resources = cb.APIResourceList(versionB1, []string{"task", "taskrun", "pipeline", "pipelinerun"}) @@ -1853,17 +2345,28 @@ func TestPipelinerunLog_follow_mode_v1beta1(t *testing.T) { } p := []*corev1.Pod{ - tbv1beta1.Pod(tr1Pod, - tbv1beta1.PodNamespace(ns), - tbv1beta1.PodLabel("tekton.dev/task", pipelineName), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer(tr1Step1Name, tr1Step1Name+":latest"), - tbv1beta1.PodContainer("nop", "override-with-nop:latest"), - ), - cb.PodStatus( - cb.PodPhase(corev1.PodSucceeded), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr1Pod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: tr1Step1Name, + Image: tr1Step1Name + ":latest", + }, + { + Name: "nop", + Image: "override-with-nop:latest", + }, + }, + }, + Status: corev1.PodStatus{ + Phase: corev1.PodPhase(corev1.PodSucceeded), + }, + }, } fakeLogStream := fake.Logs( @@ -2767,26 +3270,42 @@ func TestPipelinerunLog_finally_v1beta1(t *testing.T) { } p := []*corev1.Pod{ - tbv1beta1.Pod(tr1Pod, - tbv1beta1.PodNamespace(ns), - tbv1beta1.PodLabel("tekton.dev/task", pipelineName), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer(tr1Step1Name, tr1Step1Name+":latest"), - ), - cb.PodStatus( - cb.PodPhase(corev1.PodSucceeded), - ), - ), - tbv1beta1.Pod(finallyTrPod, - tbv1beta1.PodNamespace(ns), - tbv1beta1.PodLabel("tekton.dev/task", pipelineName), - tbv1beta1.PodSpec( - tbv1beta1.PodContainer(finallyTrStep1Name, finallyTrStep1Name+":latest"), - ), - cb.PodStatus( - cb.PodPhase(corev1.PodSucceeded), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr1Pod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: tr1Step1Name, + Image: tr1Step1Name + ":latest", + }, + }, + }, + Status: corev1.PodStatus{ + Phase: corev1.PodPhase(corev1.PodSucceeded), + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: finallyTrPod, + Namespace: ns, + Labels: map[string]string{"tekton.dev/task": pipelineName}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: finallyTrStep1Name, + Image: finallyTrStep1Name + ":latest", + }, + }, + }, + Status: corev1.PodStatus{ + Phase: corev1.PodPhase(corev1.PodSucceeded), + }, + }, } fakeLogStream := fake.Logs( diff --git a/pkg/pipelinerun/pipelinerun_test.go b/pkg/pipelinerun/pipelinerun_test.go index 6ef39ff7f..1e1305799 100644 --- a/pkg/pipelinerun/pipelinerun_test.go +++ b/pkg/pipelinerun/pipelinerun_test.go @@ -19,7 +19,6 @@ import ( "time" "github.com/jonboulle/clockwork" - tb "github.com/tektoncd/cli/internal/builder/v1alpha1" "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" @@ -29,7 +28,6 @@ import ( pipelinetest "github.com/tektoncd/pipeline/test/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) @@ -40,32 +38,55 @@ func TestPipelineRunsList_with_single_run(t *testing.T) { runDuration := 1 * time.Minute prdata := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipelinerun", tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "random"), - tb.PipelineRunStatus(), - ), - tb.PipelineRun("pipelinerun1", tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(pr1Started), - cb.PipelineRunCompletionTime(pr1Started.Add(runDuration)), - ), - ), - tb.PipelineRun("pipelinerun2", tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(pr1Started), - cb.PipelineRunCompletionTime(pr1Started.Add(runDuration)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "random"}, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun1", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr1Started}, + CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun2", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr1Started}, + CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{ PipelineRuns: prdata, @@ -283,30 +304,48 @@ func TestPipelineRunGet(t *testing.T) { runDuration := 1 * time.Minute prdata := []*v1alpha1.PipelineRun{ - tb.PipelineRun("pipelinerun1", tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(pr1Started), - cb.PipelineRunCompletionTime(pr1Started.Add(runDuration)), - ), - ), - tb.PipelineRun("pipelinerun2", tb.PipelineRunNamespace("ns"), - tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), - tb.PipelineRunSpec("pipeline"), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunStartTime(pr1Started), - cb.PipelineRunCompletionTime(pr1Started.Add(runDuration)), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun1", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr1Started}, + CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun2", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr1Started}, + CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, + }, + }, + }, } cs, _ := test.SeedTestData(t, pipelinetest.Data{ PipelineRuns: prdata, diff --git a/pkg/pipelinerun/tracker_test.go b/pkg/pipelinerun/tracker_test.go index 502c5fba2..21eb66e52 100644 --- a/pkg/pipelinerun/tracker_test.go +++ b/pkg/pipelinerun/tracker_test.go @@ -18,7 +18,6 @@ import ( "testing" "time" - tb "github.com/tektoncd/cli/internal/builder/v1alpha1" "github.com/tektoncd/cli/pkg/actions" trh "github.com/tektoncd/cli/pkg/taskrun" "github.com/tektoncd/cli/pkg/test" @@ -29,9 +28,11 @@ import ( "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" pipelinetest "github.com/tektoncd/pipeline/test/v1alpha1" corev1 "k8s.io/api/core/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" k8stest "k8s.io/client-go/testing" - "knative.dev/pkg/apis" + duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) func TestTracker_pipelinerun_complete(t *testing.T) { @@ -84,56 +85,82 @@ func TestTracker_pipelinerun_complete(t *testing.T) { for _, s := range scenarios { taskruns := []*v1alpha1.TaskRun{ - tb.TaskRun(tr1Name, tb.TaskRunNamespace(ns), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task1Name), - ), - tb.TaskRunStatus( - tb.PodName(tr1Pod), - ), - ), - tb.TaskRun(tr2Name, tb.TaskRunNamespace(ns), - tb.TaskRunSpec( - tb.TaskRunTaskRef(task2Name), - ), - tb.TaskRunStatus( - tb.PodName(tr2Pod), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr1Name, + Namespace: ns, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{ + Name: task1Name, + }, + }, + Status: v1alpha1.TaskRunStatus{ + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + PodName: tr1Pod, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: tr2Name, + Namespace: ns, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{ + Name: task2Name, + }, + }, + Status: v1alpha1.TaskRunStatus{ + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + PodName: tr2Pod, + }, + }, + }, } initialPR := []*v1alpha1.PipelineRun{ - tb.PipelineRun(prName, tb.PipelineRunNamespace(ns), - tb.PipelineRunLabel("tekton.dev/pipeline", prName), - tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionUnknown, - Reason: v1beta1.PipelineRunReasonRunning.String(), - }), - tb.PipelineRunTaskRunsStatus(tr1Name, &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: task1Name, - Status: &taskruns[0].Status, - }), - ), - ), + { + ObjectMeta: metav1.ObjectMeta{ + Name: prName, + Namespace: ns, + Labels: map[string]string{"tekton.dev/pipeline": prName}, + }, + Status: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionUnknown, + Reason: v1beta1.PipelineRunReasonRunning.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + tr1Name: {PipelineTaskName: task1Name, Status: &taskruns[0].Status}, + }, + }, + }, + }, + } + pr := &v1alpha1.PipelineRun{ + Status: v1alpha1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ + tr1Name: {PipelineTaskName: task1Name, Status: &taskruns[0].Status}, + tr2Name: {PipelineTaskName: task2Name, Status: &taskruns[1].Status}, + }, + }, + }, } - - prStatusFn := tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(apis.Condition{ - Status: corev1.ConditionTrue, - Reason: v1beta1.PipelineRunReasonSuccessful.String(), - }), - tb.PipelineRunTaskRunsStatus(tr1Name, &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: task1Name, - Status: &taskruns[0].Status, - }), - tb.PipelineRunTaskRunsStatus(tr2Name, &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: task2Name, - Status: &taskruns[1].Status, - }), - ) - pr := &v1alpha1.PipelineRun{} - prStatusFn(pr) tc := startPipelineRun(t, pipelinetest.Data{PipelineRuns: initialPR, TaskRuns: taskruns}, pr.Status) tracker := NewTracker(pipelineName, ns, tc)