Skip to content

Commit

Permalink
Replace test builders to structs in unit test for tkn pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 authored and tekton-robot committed Oct 13, 2021
1 parent 25ec930 commit 5902d22
Show file tree
Hide file tree
Showing 6 changed files with 2,952 additions and 1,108 deletions.
119 changes: 75 additions & 44 deletions pkg/cmd/pipeline/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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"
Expand All @@ -32,7 +32,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"
)

Expand All @@ -41,50 +40,82 @@ func TestPipelineDelete(t *testing.T) {
clock := clockwork.NewFakeClock()

pdata := []*v1alpha1.Pipeline{
tb.Pipeline("pipeline",
tb.PipelineNamespace("ns"),
// created 5 minutes back
cb.PipelineCreationTimestamp(clock.Now().Add(-5*time.Minute)),
),
tb.Pipeline("pipeline2",
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)},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "pipeline2",
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.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.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)),
),
),
{
ObjectMeta: metav1.ObjectMeta{
Name: "pipeline-run-1",
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(),
},
},
},
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",
Labels: map[string]string{"tekton.dev/pipeline": "pipeline"},
CreationTimestamp: metav1.Time{Time: clock.Now()},
},
Spec: v1alpha1.PipelineRunSpec{
PipelineRef: &v1alpha1.PipelineRef{
Name: "pipeline",
},
},
Status: v1alpha1.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)},
},
},
},
}
type clients struct {
pipelineClient pipelinetest.Clients
Expand Down
Loading

0 comments on commit 5902d22

Please sign in to comment.