Skip to content

Commit

Permalink
Replace test builders to structs in unit test for tkn pipelinerun
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 20, 2021
1 parent 8eded98 commit 8575a3f
Show file tree
Hide file tree
Showing 7 changed files with 2,349 additions and 1,223 deletions.
248 changes: 194 additions & 54 deletions pkg/cmd/pipelinerun/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down
Loading

0 comments on commit 8575a3f

Please sign in to comment.