From 57e94e74a2af280ab640f37f5489d81526dd6bef Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Fri, 21 Aug 2020 12:49:06 -0400 Subject: [PATCH] Migrate some test builder references to structs Also delete test/builder/ since it appears to be unused --- internal/builder/v1alpha1/condition_test.go | 124 ----- internal/builder/v1alpha1/examples_test.go | 154 ------- internal/builder/v1alpha1/param.go | 6 +- internal/builder/v1alpha1/param_test.go | 44 -- internal/builder/v1alpha1/pipeline.go | 6 +- internal/builder/v1alpha1/pipeline_test.go | 415 ----------------- internal/builder/v1alpha1/pod.go | 79 ---- internal/builder/v1alpha1/pod_test.go | 128 ------ internal/builder/v1alpha1/task.go | 4 +- internal/builder/v1alpha1/task_test.go | 426 ----------------- .../v1alpha1/condition_defaults_test.go | 106 ++--- .../pipeline/v1alpha1/condition_types_test.go | 33 +- .../v1alpha1/condition_validation_test.go | 78 ++-- .../pipeline/v1alpha1/param_types_test.go | 145 ++++-- .../v1alpha1/pipeline_validation_test.go | 199 +++++--- .../pipeline/v1alpha1/task_validation_test.go | 44 +- .../v1alpha1/taskrun_validation_test.go | 21 +- test/README.md | 29 -- test/builder/README.md | 1 - test/builder/condition.go | 72 --- test/builder/condition_test.go | 115 ----- test/builder/container.go | 87 ---- test/builder/doc.go | 63 --- test/builder/examples_test.go | 154 ------- test/builder/owner_reference.go | 39 -- test/builder/param.go | 36 -- test/builder/param_test.go | 44 -- test/builder/pipeline.go | 306 ------------- test/builder/pipeline_test.go | 415 ----------------- test/builder/pod.go | 96 ---- test/builder/pod_test.go | 128 ------ test/builder/sidecar.go | 44 -- test/builder/step.go | 84 ---- test/builder/task.go | 432 ------------------ test/builder/task_test.go | 422 ----------------- test/v1alpha1/sidecar_test.go | 48 +- test/v1alpha1/wait_test.go | 69 ++- 37 files changed, 475 insertions(+), 4221 deletions(-) delete mode 100644 internal/builder/v1alpha1/condition_test.go delete mode 100644 internal/builder/v1alpha1/examples_test.go delete mode 100644 internal/builder/v1alpha1/param_test.go delete mode 100644 internal/builder/v1alpha1/pipeline_test.go delete mode 100644 internal/builder/v1alpha1/pod.go delete mode 100644 internal/builder/v1alpha1/pod_test.go delete mode 100644 internal/builder/v1alpha1/task_test.go delete mode 120000 test/builder/README.md delete mode 100644 test/builder/condition.go delete mode 100644 test/builder/condition_test.go delete mode 100644 test/builder/container.go delete mode 100644 test/builder/doc.go delete mode 100644 test/builder/examples_test.go delete mode 100644 test/builder/owner_reference.go delete mode 100644 test/builder/param.go delete mode 100644 test/builder/param_test.go delete mode 100644 test/builder/pipeline.go delete mode 100644 test/builder/pipeline_test.go delete mode 100644 test/builder/pod.go delete mode 100644 test/builder/pod_test.go delete mode 100644 test/builder/sidecar.go delete mode 100644 test/builder/step.go delete mode 100644 test/builder/task.go delete mode 100644 test/builder/task_test.go diff --git a/internal/builder/v1alpha1/condition_test.go b/internal/builder/v1alpha1/condition_test.go deleted file mode 100644 index e72474b24e1..00000000000 --- a/internal/builder/v1alpha1/condition_test.go +++ /dev/null @@ -1,124 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" -) - -func TestCondition(t *testing.T) { - condition := tb.Condition("cond-name", - tb.ConditionNamespace("foo"), - tb.ConditionLabels( - map[string]string{ - "label-1": "label-value-1", - "label-2": "label-value-2", - }), - tb.ConditionAnnotations( - map[string]string{ - "annotation-1": "annotation-value-1", - "annotation-2": "annotation-value-2", - }), - tb.ConditionSpec(tb.ConditionSpecCheck("", "ubuntu", tb.Command("exit 0")), - tb.ConditionDescription("Test Condition"), - tb.ConditionParamSpec("param-1", v1alpha1.ParamTypeString, - tb.ParamSpecDefault("default"), - tb.ParamSpecDescription("desc")), - tb.ConditionResource("git-resource", v1alpha1.PipelineResourceTypeGit), - tb.ConditionResource("pr", v1alpha1.PipelineResourceTypePullRequest), - ), - ) - - expected := &v1alpha1.Condition{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cond-name", - Namespace: "foo", - Labels: map[string]string{ - "label-1": "label-value-1", - "label-2": "label-value-2", - }, - Annotations: map[string]string{ - "annotation-1": "annotation-value-1", - "annotation-2": "annotation-value-2", - }, - }, - Spec: v1alpha1.ConditionSpec{ - Check: v1alpha1.Step{ - Container: corev1.Container{ - Image: "ubuntu", - Command: []string{"exit 0"}, - }, - }, - Description: "Test Condition", - Params: []v1alpha1.ParamSpec{{ - Name: "param-1", - Type: v1alpha1.ParamTypeString, - Description: "desc", - Default: &v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeString, - StringVal: "default", - }}}, - Resources: []v1alpha1.ResourceDeclaration{{ - Name: "git-resource", - Type: "git", - }, { - Name: "pr", - Type: "pullRequest", - }}, - }, - } - - if d := cmp.Diff(expected, condition); d != "" { - t.Fatalf("Condition diff -want, +got: %v", d) - } -} - -func TestConditionWithScript(t *testing.T) { - condition := tb.Condition("cond-name", - tb.ConditionNamespace("foo"), - tb.ConditionSpec(tb.ConditionSpecCheck("", "ubuntu"), - tb.ConditionSpecCheckScript("ls /tmp"), - ), - ) - - expected := &v1alpha1.Condition{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cond-name", - Namespace: "foo", - }, - Spec: v1alpha1.ConditionSpec{ - Check: v1alpha1.Step{ - Container: corev1.Container{ - Image: "ubuntu", - }, - Script: "ls /tmp", - }, - }, - } - - if d := cmp.Diff(expected, condition); d != "" { - t.Fatalf("Condition diff -want, +got: %v", d) - } - -} diff --git a/internal/builder/v1alpha1/examples_test.go b/internal/builder/v1alpha1/examples_test.go deleted file mode 100644 index 42928a77db0..00000000000 --- a/internal/builder/v1alpha1/examples_test.go +++ /dev/null @@ -1,154 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" -) - -// This is a "hack" to make the example "look" like tests -var t *testing.T - -func ExampleTask() { - // You can declare re-usable modifiers - myStep := tb.Step("myimage") - // … and use them in a Task definition - myTask := tb.Task("my-task", tb.TaskSpec( - tb.Step("myotherimage", tb.StepCommand("/mycmd")), - myStep, - )) - // … and another one. - myOtherTask := tb.Task("my-other-task", - tb.TaskSpec(myStep, - tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit)), - ), - ) - expectedTask := &v1alpha1.Task{ - // […] - } - expectedOtherTask := &v1alpha1.Task{ - // […] - } - // […] - if d := cmp.Diff(expectedTask, myTask); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } - if d := cmp.Diff(expectedOtherTask, myOtherTask); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func ExampleClusterTask() { - myClusterTask := tb.ClusterTask("my-task", tb.ClusterTaskSpec( - tb.Step("myotherimage", tb.StepCommand("/mycmd")), - )) - expectedClusterTask := &v1alpha1.Task{ - // […] - } - // […] - if d := cmp.Diff(expectedClusterTask, myClusterTask); d != "" { - t.Fatalf("ClusterTask diff -want, +got: %v", d) - } -} - -func ExampleTaskRun() { - // A simple definition, with a Task reference - myTaskRun := tb.TaskRun("my-taskrun", tb.TaskRunSpec( - tb.TaskRunTaskRef("my-task"), - )) - // … or a more complex one with inline TaskSpec - myTaskRunWithSpec := tb.TaskRun("my-taskrun-with-spec", tb.TaskRunSpec( - tb.TaskRunInputs( - tb.TaskRunInputsParam("myarg", "foo"), - tb.TaskRunInputsResource("workspace", tb.TaskResourceBindingRef("git-resource")), - ), - tb.TaskRunTaskSpec( - tb.TaskInputs( - tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit), - tb.InputsParamSpec("myarg", v1alpha1.ParamTypeString, tb.ParamSpecDefault("mydefault")), - ), - tb.Step("myimage", tb.StepCommand("/mycmd"), - tb.StepArgs("--my-arg=$(inputs.params.myarg)"), - ), - ), - )) - expectedTaskRun := &v1alpha1.TaskRun{ - // […] - } - expectedTaskRunWithSpec := &v1alpha1.TaskRun{ - // […] - } - // […] - if d := cmp.Diff(expectedTaskRun, myTaskRun); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } - if d := cmp.Diff(expectedTaskRunWithSpec, myTaskRunWithSpec); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func ExamplePipeline() { - pipeline := tb.Pipeline("tomatoes", - tb.PipelineSpec(tb.PipelineTask("foo", "banana")), - ) - expectedPipeline := &v1alpha1.Pipeline{ - // […] - } - // […] - if d := cmp.Diff(expectedPipeline, pipeline); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func ExamplePipelineRun() { - pipelineRun := tb.PipelineRun("pear", - tb.PipelineRunSpec("tomatoes", tb.PipelineRunServiceAccountName("inexistent")), - ) - expectedPipelineRun := &v1alpha1.PipelineRun{ - // […] - } - // […] - if d := cmp.Diff(expectedPipelineRun, pipelineRun); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func ExamplePipelineResource() { - gitResource := tb.PipelineResource("git-resource", tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "https://foo.git"), - )) - imageResource := tb.PipelineResource("image-resource", tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeImage, tb.PipelineResourceSpecParam("URL", "gcr.io/kristoff/sven"), - )) - expectedGitResource := v1alpha1.PipelineResource{ - // […] - } - expectedImageResource := v1alpha1.PipelineResource{ - // […] - } - // […] - if d := cmp.Diff(expectedGitResource, gitResource); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } - if d := cmp.Diff(expectedImageResource, imageResource); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} diff --git a/internal/builder/v1alpha1/param.go b/internal/builder/v1alpha1/param.go index bcc7ca54c30..b9a84276680 100644 --- a/internal/builder/v1alpha1/param.go +++ b/internal/builder/v1alpha1/param.go @@ -18,9 +18,9 @@ import "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" // ParamSpecOp is an operation which modify a ParamSpec struct. type ParamSpecOp func(*v1alpha1.ParamSpec) -// ArrayOrString creates an ArrayOrString of type ParamTypeString or ParamTypeArray, based on +// arrayOrString creates an ArrayOrString of type ParamTypeString or ParamTypeArray, based on // how many inputs are given (>1 input will create an array, not string). -func ArrayOrString(value string, additionalValues ...string) *v1alpha1.ArrayOrString { +func arrayOrString(value string, additionalValues ...string) *v1alpha1.ArrayOrString { if len(additionalValues) > 0 { additionalValues = append([]string{value}, additionalValues...) return &v1alpha1.ArrayOrString{ @@ -43,7 +43,7 @@ func ParamSpecDescription(desc string) ParamSpecOp { // ParamSpecDefault sets the default value of a ParamSpec. func ParamSpecDefault(value string, additionalValues ...string) ParamSpecOp { - arrayOrString := ArrayOrString(value, additionalValues...) + arrayOrString := arrayOrString(value, additionalValues...) return func(ps *v1alpha1.ParamSpec) { ps.Default = arrayOrString } diff --git a/internal/builder/v1alpha1/param_test.go b/internal/builder/v1alpha1/param_test.go deleted file mode 100644 index 08aa93b9fca..00000000000 --- a/internal/builder/v1alpha1/param_test.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright 2019 The Tekton Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" -) - -func TestGenerateString(t *testing.T) { - value := tb.ArrayOrString("somestring") - expectedValue := &v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeString, - StringVal: "somestring", - } - if d := cmp.Diff(expectedValue, value); d != "" { - t.Fatalf("ArrayOrString diff -want, +got: %v", d) - } -} - -func TestGenerateArray(t *testing.T) { - value := tb.ArrayOrString("some", "array", "elements") - expectedValue := &v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeArray, - ArrayVal: []string{"some", "array", "elements"}, - } - if d := cmp.Diff(expectedValue, value); d != "" { - t.Fatalf("ArrayOrString diff -want, +got: %v", d) - } -} diff --git a/internal/builder/v1alpha1/pipeline.go b/internal/builder/v1alpha1/pipeline.go index a1c4acc9189..ce567a4055a 100644 --- a/internal/builder/v1alpha1/pipeline.go +++ b/internal/builder/v1alpha1/pipeline.go @@ -213,7 +213,7 @@ func PipelineTaskRefKind(kind v1alpha1.TaskKind) PipelineTaskOp { // PipelineTaskParam adds a ResourceParam, with specified name and value, to the PipelineTask. func PipelineTaskParam(name string, value string, additionalValues ...string) PipelineTaskOp { - arrayOrString := ArrayOrString(value, additionalValues...) + arrayOrString := arrayOrString(value, additionalValues...) return func(pt *v1alpha1.PipelineTask) { pt.Params = append(pt.Params, v1alpha1.Param{ Name: name, @@ -287,7 +287,7 @@ func PipelineTaskConditionParam(name, val string) PipelineTaskConditionOp { } condition.Params = append(condition.Params, v1alpha1.Param{ Name: name, - Value: *ArrayOrString(val), + Value: *arrayOrString(val), }) } } @@ -436,7 +436,7 @@ func PipelineRunServiceAccountNameTask(taskName, sa string) PipelineRunSpecOp { // PipelineRunParam add a param, with specified name and value, to the PipelineRunSpec. func PipelineRunParam(name string, value string, additionalValues ...string) PipelineRunSpecOp { - arrayOrString := ArrayOrString(value, additionalValues...) + arrayOrString := arrayOrString(value, additionalValues...) return func(prs *v1alpha1.PipelineRunSpec) { prs.Params = append(prs.Params, v1alpha1.Param{ Name: name, diff --git a/internal/builder/v1alpha1/pipeline_test.go b/internal/builder/v1alpha1/pipeline_test.go deleted file mode 100644 index 8227fc7bba0..00000000000 --- a/internal/builder/v1alpha1/pipeline_test.go +++ /dev/null @@ -1,415 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - "time" - - "github.com/google/go-cmp/cmp" - 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" - - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" -) - -func TestPipeline(t *testing.T) { - creationTime := time.Now() - - pipeline := tb.Pipeline("tomatoes", tb.PipelineNamespace("foo"), tb.PipelineSpec( - tb.PipelineDeclaredResource("my-only-git-resource", "git"), - tb.PipelineDeclaredResource("my-only-image-resource", "image"), - tb.PipelineDescription("Test Pipeline"), - tb.PipelineParamSpec("first-param", v1alpha1.ParamTypeString, tb.ParamSpecDefault("default-value"), tb.ParamSpecDescription("default description")), - tb.PipelineTask("foo", "banana", - tb.PipelineTaskParam("stringparam", "value"), - tb.PipelineTaskParam("arrayparam", "array", "value"), - tb.PipelineTaskCondition("some-condition-ref", - tb.PipelineTaskConditionParam("param-name", "param-value"), - tb.PipelineTaskConditionResource("some-resource", "my-only-git-resource", "bar", "never-gonna"), - ), - tb.PipelineTaskWorkspaceBinding("task-workspace1", "workspace1", ""), - ), - tb.PipelineTask("bar", "chocolate", - tb.PipelineTaskRefKind(v1alpha1.ClusterTaskKind), - tb.PipelineTaskInputResource("some-repo", "my-only-git-resource", tb.From("foo")), - tb.PipelineTaskOutputResource("some-image", "my-only-image-resource"), - ), - tb.PipelineTask("never-gonna", "give-you-up", - tb.RunAfter("foo"), - tb.PipelineTaskTimeout(5*time.Second), - ), - tb.PipelineTask("foo", "", tb.PipelineTaskSpec(&v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "step", - Image: "myimage", - }}}, - }}, - )), - tb.PipelineWorkspaceDeclaration("workspace1"), - ), - tb.PipelineCreationTimestamp(creationTime), - ) - expectedPipeline := &v1alpha1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{ - Name: "tomatoes", Namespace: "foo", - CreationTimestamp: metav1.Time{Time: creationTime}, - }, - Spec: v1alpha1.PipelineSpec{ - Resources: []v1alpha1.PipelineDeclaredResource{{ - Name: "my-only-git-resource", - Type: "git", - }, { - Name: "my-only-image-resource", - Type: "image", - }}, - Description: "Test Pipeline", - Params: []v1alpha1.ParamSpec{{ - Name: "first-param", - Type: v1alpha1.ParamTypeString, - Default: tb.ArrayOrString("default-value"), - Description: "default description", - }}, - Tasks: []v1alpha1.PipelineTask{{ - Name: "foo", - TaskRef: &v1alpha1.TaskRef{Name: "banana"}, - Params: []v1alpha1.Param{{ - Name: "stringparam", - Value: *tb.ArrayOrString("value"), - }, { - Name: "arrayparam", - Value: *tb.ArrayOrString("array", "value"), - }}, - Conditions: []v1alpha1.PipelineTaskCondition{{ - ConditionRef: "some-condition-ref", - Params: []v1alpha1.Param{{ - Name: "param-name", - Value: v1alpha1.ArrayOrString{ - Type: "string", - StringVal: "param-value", - }, - }}, - Resources: []v1alpha1.PipelineTaskInputResource{{ - Name: "some-resource", - Resource: "my-only-git-resource", - From: []string{"bar", "never-gonna"}, - }}, - }}, - Workspaces: []v1alpha1.WorkspacePipelineTaskBinding{{ - Name: "task-workspace1", - Workspace: "workspace1", - }}, - }, { - Name: "bar", - TaskRef: &v1alpha1.TaskRef{Name: "chocolate", Kind: v1alpha1.ClusterTaskKind}, - Resources: &v1alpha1.PipelineTaskResources{ - Inputs: []v1alpha1.PipelineTaskInputResource{{ - Name: "some-repo", - Resource: "my-only-git-resource", - From: []string{"foo"}, - }}, - Outputs: []v1alpha1.PipelineTaskOutputResource{{ - Name: "some-image", - Resource: "my-only-image-resource", - }}, - }, - }, { - Name: "never-gonna", - TaskRef: &v1alpha1.TaskRef{Name: "give-you-up"}, - RunAfter: []string{"foo"}, - Timeout: &metav1.Duration{Duration: 5 * time.Second}, - }, { - Name: "foo", - TaskSpec: &v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "step", - Image: "myimage", - }}}, - }}, - }}, - Workspaces: []v1alpha1.PipelineWorkspaceDeclaration{{ - Name: "workspace1", - }}, - }, - } - if d := cmp.Diff(expectedPipeline, pipeline); d != "" { - t.Fatalf("Pipeline diff -want, +got: %v", d) - } -} - -func TestPipelineRun(t *testing.T) { - startTime := time.Now() - completedTime := startTime.Add(5 * time.Minute) - - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec( - "tomatoes", tb.PipelineRunServiceAccountName("sa"), - tb.PipelineRunParam("first-param-string", "first-value"), - tb.PipelineRunParam("second-param-array", "some", "array"), - tb.PipelineRunTimeout(1*time.Hour), - tb.PipelineRunResourceBinding("some-resource", tb.PipelineResourceBindingRef("my-special-resource")), - tb.PipelineRunServiceAccountNameTask("foo", "sa-2"), - ), tb.PipelineRunStatus(tb.PipelineRunStatusCondition( - apis.Condition{Type: apis.ConditionSucceeded}), - tb.PipelineRunStartTime(startTime), - tb.PipelineRunCompletionTime(completedTime), - tb.PipelineRunTaskRunsStatus("trname", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "task-1", - }), - ), tb.PipelineRunLabel("label-key", "label-value")) - expectedPipelineRun := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pear", - Namespace: "foo", - Labels: map[string]string{ - "label-key": "label-value", - }, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{Name: "tomatoes"}, - ServiceAccountName: "sa", - ServiceAccountNames: []v1alpha1.PipelineRunSpecServiceAccountName{{TaskName: "foo", ServiceAccountName: "sa-2"}}, - Params: []v1alpha1.Param{{ - Name: "first-param-string", - Value: *tb.ArrayOrString("first-value"), - }, { - Name: "second-param-array", - Value: *tb.ArrayOrString("some", "array"), - }}, - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - Resources: []v1alpha1.PipelineResourceBinding{{ - Name: "some-resource", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "my-special-resource", - }, - }}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}}, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: startTime}, - CompletionTime: &metav1.Time{Time: completedTime}, - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ - "trname": {PipelineTaskName: "task-1"}, - }, - }, - }, - } - if d := cmp.Diff(expectedPipelineRun, pipelineRun); d != "" { - t.Fatalf("PipelineRun diff -want, +got: %v", d) - } -} - -func TestPipelineRunWithPodTemplate(t *testing.T) { - startTime := time.Now() - completedTime := startTime.Add(5 * time.Minute) - - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec( - "tomatoes", tb.PipelineRunServiceAccountName("sa"), - tb.PipelineRunParam("first-param-string", "first-value"), - tb.PipelineRunParam("second-param-array", "some", "array"), - tb.PipelineRunTimeout(1*time.Hour), - tb.PipelineRunResourceBinding("some-resource", tb.PipelineResourceBindingRef("my-special-resource")), - tb.PipelineRunServiceAccountNameTask("foo", "sa-2"), - tb.PipelineRunNodeSelector(map[string]string{ - "label": "value", - }), - ), tb.PipelineRunStatus(tb.PipelineRunStatusCondition( - apis.Condition{Type: apis.ConditionSucceeded}), - tb.PipelineRunStartTime(startTime), - tb.PipelineRunCompletionTime(completedTime), - tb.PipelineRunTaskRunsStatus("trname", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "task-1", - }), - ), tb.PipelineRunLabel("label-key", "label-value")) - expectedPipelineRun := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pear", - Namespace: "foo", - Labels: map[string]string{ - "label-key": "label-value", - }, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{Name: "tomatoes"}, - ServiceAccountName: "sa", - ServiceAccountNames: []v1alpha1.PipelineRunSpecServiceAccountName{{TaskName: "foo", ServiceAccountName: "sa-2"}}, - Params: []v1alpha1.Param{{ - Name: "first-param-string", - Value: *tb.ArrayOrString("first-value"), - }, { - Name: "second-param-array", - Value: *tb.ArrayOrString("some", "array"), - }}, - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - Resources: []v1alpha1.PipelineResourceBinding{{ - Name: "some-resource", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "my-special-resource", - }, - }}, - PodTemplate: &v1alpha1.PodTemplate{ - NodeSelector: map[string]string{ - "label": "value", - }, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}}, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: startTime}, - CompletionTime: &metav1.Time{Time: completedTime}, - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ - "trname": {PipelineTaskName: "task-1"}, - }, - }, - }, - } - if d := cmp.Diff(expectedPipelineRun, pipelineRun); d != "" { - t.Fatalf("PipelineRun diff -want, +got: %v", d) - } -} - -func TestPipelineRunWithResourceSpec(t *testing.T) { - startTime := time.Now() - completedTime := startTime.Add(5 * time.Minute) - - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec( - "tomatoes", tb.PipelineRunServiceAccountName("sa"), - tb.PipelineRunParam("first-param-string", "first-value"), - tb.PipelineRunParam("second-param-array", "some", "array"), - tb.PipelineRunTimeout(1*time.Hour), - tb.PipelineRunResourceBinding("some-resource", - tb.PipelineResourceBindingResourceSpec(&v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.ResourceParam{{ - Name: "url", - Value: "git", - }}})), - tb.PipelineRunServiceAccountNameTask("foo", "sa-2"), - ), tb.PipelineRunStatus(tb.PipelineRunStatusCondition( - apis.Condition{Type: apis.ConditionSucceeded}), - tb.PipelineRunStartTime(startTime), - tb.PipelineRunCompletionTime(completedTime), - tb.PipelineRunTaskRunsStatus("trname", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "task-1", - }), - ), tb.PipelineRunLabel("label-key", "label-value")) - expectedPipelineRun := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pear", - Namespace: "foo", - Labels: map[string]string{ - "label-key": "label-value", - }, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{Name: "tomatoes"}, - ServiceAccountName: "sa", - ServiceAccountNames: []v1alpha1.PipelineRunSpecServiceAccountName{{TaskName: "foo", ServiceAccountName: "sa-2"}}, - Params: []v1alpha1.Param{{ - Name: "first-param-string", - Value: *tb.ArrayOrString("first-value"), - }, { - Name: "second-param-array", - Value: *tb.ArrayOrString("some", "array"), - }}, - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - Resources: []v1alpha1.PipelineResourceBinding{{ - Name: "some-resource", - ResourceSpec: &v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceType("git"), - Params: []v1alpha1.ResourceParam{{ - Name: "url", - Value: "git", - }}, - SecretParams: nil, - }, - }}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}}, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: startTime}, - CompletionTime: &metav1.Time{Time: completedTime}, - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ - "trname": {PipelineTaskName: "task-1"}, - }, - }, - }, - } - if d := cmp.Diff(expectedPipelineRun, pipelineRun); d != "" { - t.Fatalf("PipelineRun diff -want, +got: %v", d) - } -} - -func TestPipelineRunWithPipelineSpec(t *testing.T) { - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec("", tb.PipelineRunPipelineSpec( - tb.PipelineTask("a-task", "some-task")), - tb.PipelineRunServiceAccountName("sa"), - )) - - expectedPipelineRun := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pear", - Namespace: "foo", - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: nil, - PipelineSpec: &v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{{ - Name: "a-task", - TaskRef: &v1alpha1.TaskRef{Name: "some-task"}, - }}, - }, - ServiceAccountName: "sa", - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - }, - } - - if diff := cmp.Diff(expectedPipelineRun, pipelineRun); diff != "" { - t.Fatalf("PipelineRun diff -want, +got: %s", diff) - } -} - -func TestPipelineResource(t *testing.T) { - pipelineResource := tb.PipelineResource("git-resource", tb.PipelineResourceNamespace("foo"), tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "https://foo.git"), tb.PipelineResourceDescription("test description"), - )) - expectedPipelineResource := &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{Name: "git-resource", Namespace: "foo"}, - Spec: v1alpha1.PipelineResourceSpec{ - Description: "test description", - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.ResourceParam{{ - Name: "URL", Value: "https://foo.git", - }}, - }, - } - if d := cmp.Diff(expectedPipelineResource, pipelineResource); d != "" { - t.Fatalf("PipelineResource diff -want, +got: %v", d) - } -} diff --git a/internal/builder/v1alpha1/pod.go b/internal/builder/v1alpha1/pod.go deleted file mode 100644 index a69b902ab30..00000000000 --- a/internal/builder/v1alpha1/pod.go +++ /dev/null @@ -1,79 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1beta1 "github.com/tektoncd/pipeline/internal/builder/v1beta1" -) - -// PodOp is an operation which modifies a Pod struct. -type PodOp = v1beta1.PodOp - -// PodSpecOp is an operation which modifies a PodSpec struct. -type PodSpecOp = v1beta1.PodSpecOp - -// PodStatusOp is an operation which modifies a PodStatus struct. -type PodStatusOp = v1beta1.PodStatusOp - -var ( - // Pod creates a Pod with default values. - // Any number of Pod modifiers can be passed to transform it. - Pod = v1beta1.Pod - - // PodNamespace sets the namespace on the Pod. - PodNamespace = v1beta1.PodNamespace - - // PodAnnotation adds an annotation to the Pod. - PodAnnotation = v1beta1.PodAnnotation - - // PodLabel adds a label to the Pod. - PodLabel = v1beta1.PodLabel - - // PodOwnerReference adds an OwnerReference, with specified kind and name, to the Pod. - PodOwnerReference = v1beta1.PodOwnerReference - - // PodSpec creates a PodSpec with default values. - // Any number of PodSpec modifiers can be passed to transform it. - PodSpec = v1beta1.PodSpec - - // PodRestartPolicy sets the restart policy on the PodSpec. - PodRestartPolicy = v1beta1.PodRestartPolicy - - // PodServiceAccountName sets the service account on the PodSpec. - PodServiceAccountName = v1beta1.PodServiceAccountName - - // PodContainer adds a Container, with the specified name and image, to the PodSpec. - // Any number of Container modifiers can be passed to transform it. - PodContainer = v1beta1.PodContainer - - // PodInitContainer adds an InitContainer, with the specified name and image, to the PodSpec. - // Any number of Container modifiers can be passed to transform it. - PodInitContainer = v1beta1.PodInitContainer - - // PodVolumes sets the Volumes on the PodSpec. - PodVolumes = v1beta1.PodVolumes - - // PodCreationTimestamp sets the creation time of the pod - PodCreationTimestamp = v1beta1.PodCreationTimestamp - - // PodStatus creates a PodStatus with default values. - // Any number of PodStatus modifiers can be passed to transform it. - PodStatus = v1beta1.PodStatus - - // PodStatusConditions adds a Conditions (set) to the Pod status. - PodStatusConditions = v1beta1.PodStatusConditions -) diff --git a/internal/builder/v1alpha1/pod_test.go b/internal/builder/v1alpha1/pod_test.go deleted file mode 100644 index aaa4b875eb4..00000000000 --- a/internal/builder/v1alpha1/pod_test.go +++ /dev/null @@ -1,128 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestPod(t *testing.T) { - trueB := true - resourceQuantityCmp := cmp.Comparer(func(x, y resource.Quantity) bool { - return x.Cmp(y) == 0 - }) - volume := corev1.Volume{ - Name: "tools-volume", - VolumeSource: corev1.VolumeSource{}, - } - got := tb.Pod("foo-pod-123456", - tb.PodNamespace("foo"), - tb.PodAnnotation("annotation", "annotation-value"), - tb.PodLabel("label", "label-value"), - tb.PodOwnerReference("TaskRun", "taskrun-foo", - tb.OwnerReferenceAPIVersion("a1")), - tb.PodSpec( - tb.PodServiceAccountName("sa"), - tb.PodRestartPolicy(corev1.RestartPolicyNever), - tb.PodContainer("nop", "nop:latest"), - tb.PodInitContainer("basic", "ubuntu", - tb.Command("ls", "-l"), - tb.Args(), - tb.WorkingDir("/workspace"), - tb.EnvVar("HOME", "/tekton/home"), - tb.VolumeMount("tools-volume", "/tools"), - tb.Resources( - tb.Limits(tb.Memory("1.5Gi")), - tb.Requests( - tb.CPU("100m"), - tb.Memory("1Gi"), - tb.EphemeralStorage("500Mi"), - ), - ), - ), - tb.PodVolumes(volume), - ), - ) - want := &corev1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "foo-pod-123456", - Annotations: map[string]string{ - "annotation": "annotation-value", - }, - Labels: map[string]string{ - "label": "label-value", - }, - OwnerReferences: []metav1.OwnerReference{{ - Kind: "TaskRun", - Name: "taskrun-foo", - APIVersion: "a1", - Controller: &trueB, - BlockOwnerDeletion: &trueB, - }}, - }, - Spec: corev1.PodSpec{ - ServiceAccountName: "sa", - RestartPolicy: corev1.RestartPolicyNever, - Containers: []corev1.Container{{ - Name: "nop", - Image: "nop:latest", - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("0"), - corev1.ResourceMemory: resource.MustParse("0"), - corev1.ResourceEphemeralStorage: resource.MustParse("0"), - }, - }, - }}, - InitContainers: []corev1.Container{{ - Name: "basic", - Image: "ubuntu", - Command: []string{"ls", "-l"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{{ - Name: "HOME", - Value: "/tekton/home", - }}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "tools-volume", - MountPath: "/tools", - }}, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse("1.5Gi"), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("100m"), - corev1.ResourceMemory: resource.MustParse("1Gi"), - corev1.ResourceEphemeralStorage: resource.MustParse("500Mi"), - }, - }, - }}, - Volumes: []corev1.Volume{volume}, - }, - } - if d := cmp.Diff(want, got, resourceQuantityCmp); d != "" { - t.Fatalf("Pod diff -want, +got: %v", d) - } -} diff --git a/internal/builder/v1alpha1/task.go b/internal/builder/v1alpha1/task.go index 9e499391202..be77e5133f1 100644 --- a/internal/builder/v1alpha1/task.go +++ b/internal/builder/v1alpha1/task.go @@ -757,7 +757,7 @@ func TaskRunServiceAccountName(sa string) TaskRunSpecOp { // TaskRunParam sets the Params to the TaskSpec func TaskRunParam(name, value string, additionalValues ...string) TaskRunSpecOp { - arrayOrString := ArrayOrString(value, additionalValues...) + arrayOrString := arrayOrString(value, additionalValues...) return func(spec *v1alpha1.TaskRunSpec) { spec.Params = append(spec.Params, v1alpha1.Param{ Name: name, @@ -822,7 +822,7 @@ func TaskRunInputs(ops ...TaskRunInputsOp) TaskRunSpecOp { // TaskRunInputsParam add a param, with specified name and value, to the TaskRunInputs. func TaskRunInputsParam(name, value string, additionalValues ...string) TaskRunInputsOp { - arrayOrString := ArrayOrString(value, additionalValues...) + arrayOrString := arrayOrString(value, additionalValues...) return func(i *v1alpha1.TaskRunInputs) { i.Params = append(i.Params, v1alpha1.Param{ Name: name, diff --git a/internal/builder/v1alpha1/task_test.go b/internal/builder/v1alpha1/task_test.go deleted file mode 100644 index d3d9e038e29..00000000000 --- a/internal/builder/v1alpha1/task_test.go +++ /dev/null @@ -1,426 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - "time" - - "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/config" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - 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" -) - -var ( - gitResource = tb.PipelineResource("git-resource", tb.PipelineResourceNamespace("foo"), tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "https://foo.git"), - )) - anotherGitResource = tb.PipelineResource("another-git-resource", tb.PipelineResourceNamespace("foo"), tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "https://foobar.git"), - )) -) - -func TestTask(t *testing.T) { - task := tb.Task("test-task", tb.TaskType(), tb.TaskSpec( - tb.TaskInputs( - tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit, tb.ResourceTargetPath("/foo/bar")), - tb.InputsResource("optional_workspace", v1alpha1.PipelineResourceTypeGit, tb.ResourceOptional(true)), - tb.InputsParamSpec("param", v1alpha1.ParamTypeString, tb.ParamSpecDescription("mydesc"), tb.ParamSpecDefault("default")), - tb.InputsParamSpec("array-param", v1alpha1.ParamTypeString, tb.ParamSpecDescription("desc"), tb.ParamSpecDefault("array", "values")), - ), - tb.TaskOutputs( - tb.OutputsResource("myotherimage", v1alpha1.PipelineResourceTypeImage), - tb.OutputsResource("myoptionalimage", v1alpha1.PipelineResourceTypeImage, tb.ResourceOptional(true)), - ), - tb.TaskDescription("Test Task"), - tb.Step("myimage", tb.StepName("mycontainer"), tb.StepCommand("/mycmd"), tb.StepArgs( - "--my-other-arg=$(inputs.resources.workspace.url)", - )), - tb.Step("myimage2", tb.StepScript("echo foo")), - tb.TaskVolume("foo", tb.VolumeSource(corev1.VolumeSource{ - HostPath: &corev1.HostPathVolumeSource{Path: "/foo/bar"}, - })), - tb.TaskStepTemplate( - tb.EnvVar("FRUIT", "BANANA"), - ), - tb.TaskWorkspace("bread", "kind of bread", "/bread/path", false), - ), tb.TaskNamespace("foo")) - expectedTask := &v1alpha1.Task{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "tekton.dev/v1alpha1", - Kind: "Task", - }, - ObjectMeta: metav1.ObjectMeta{Name: "test-task", Namespace: "foo"}, - Spec: v1alpha1.TaskSpec{ - TaskSpec: v1beta1.TaskSpec{ - Description: "Test Task", - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "mycontainer", - Image: "myimage", - Command: []string{"/mycmd"}, - Args: []string{"--my-other-arg=$(inputs.resources.workspace.url)"}, - }}, {Script: "echo foo", Container: corev1.Container{ - Image: "myimage2", - }}}, - Volumes: []corev1.Volume{{ - Name: "foo", - VolumeSource: corev1.VolumeSource{ - HostPath: &corev1.HostPathVolumeSource{Path: "/foo/bar"}, - }, - }}, - StepTemplate: &corev1.Container{ - Env: []corev1.EnvVar{{ - Name: "FRUIT", - Value: "BANANA", - }}, - }, - Workspaces: []v1alpha1.WorkspaceDeclaration{{ - Name: "bread", - Description: "kind of bread", - MountPath: "/bread/path", - ReadOnly: false, - }}, - }, - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "workspace", - Type: v1alpha1.PipelineResourceTypeGit, - TargetPath: "/foo/bar", - }}, { - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "optional_workspace", - Type: v1alpha1.PipelineResourceTypeGit, - TargetPath: "", - Optional: true, - }}}, - Params: []v1alpha1.ParamSpec{{ - Name: "param", - Type: v1alpha1.ParamTypeString, - Description: "mydesc", - Default: tb.ArrayOrString("default"), - }, { - Name: "array-param", - Type: v1alpha1.ParamTypeString, - Description: "desc", - Default: tb.ArrayOrString("array", "values"), - }}}, - Outputs: &v1alpha1.Outputs{ - Resources: []v1alpha1.TaskResource{{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "myotherimage", - Type: v1alpha1.PipelineResourceTypeImage, - }}, { - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "myoptionalimage", - Type: v1alpha1.PipelineResourceTypeImage, - TargetPath: "", - Optional: true, - }}}, - }, - }, - } - if d := cmp.Diff(expectedTask, task); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func TestClusterTask(t *testing.T) { - task := tb.ClusterTask("test-clustertask", tb.ClusterTaskType(), tb.ClusterTaskSpec( - tb.Step("myimage", tb.StepCommand("/mycmd"), tb.StepArgs( - "--my-other-arg=$(inputs.resources.workspace.url)", - )), - )) - expectedTask := &v1alpha1.ClusterTask{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "tekton.dev/v1alpha1", - Kind: "ClusterTask", - }, - ObjectMeta: metav1.ObjectMeta{Name: "test-clustertask"}, - Spec: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Image: "myimage", - Command: []string{"/mycmd"}, - Args: []string{"--my-other-arg=$(inputs.resources.workspace.url)"}, - }}}, - }}, - } - if d := cmp.Diff(expectedTask, task); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func TestTaskRunWithTaskRef(t *testing.T) { - var trueB = true - terminatedState := corev1.ContainerStateTerminated{Reason: "Completed"} - - taskRun := tb.TaskRun("test-taskrun", - tb.TaskRunNamespace("foo"), - tb.TaskRunOwnerReference("PipelineRun", "test", - tb.OwnerReferenceAPIVersion("a1"), - tb.Controller, tb.BlockOwnerDeletion, - ), - tb.TaskRunLabels(map[string]string{"label-2": "label-value-2", "label-3": "label-value-3"}), - tb.TaskRunLabel("label", "label-value"), - tb.TaskRunAnnotations(map[string]string{"annotation-1": "annotation-value-1", "annotation-2": "annotation-value-2"}), - tb.TaskRunSpec( - tb.TaskRunTaskRef("task-output", - tb.TaskRefKind(v1alpha1.ClusterTaskKind), - tb.TaskRefAPIVersion("a1"), - ), - tb.TaskRunInputs( - tb.TaskRunInputsResource(gitResource.Name, - tb.TaskResourceBindingRef("my-git"), - tb.TaskResourceBindingPaths("source-folder"), - tb.TaskResourceBindingRefAPIVersion("a1"), - ), - tb.TaskRunInputsResource(anotherGitResource.Name, - tb.TaskResourceBindingPaths("source-folder"), - tb.TaskResourceBindingResourceSpec(&v1alpha1.PipelineResourceSpec{Type: v1alpha1.PipelineResourceTypeCluster}), - ), - tb.TaskRunInputsParam("iparam", "ivalue"), - tb.TaskRunInputsParam("arrayparam", "array", "values"), - ), - tb.TaskRunOutputs( - tb.TaskRunOutputsResource(gitResource.Name, - tb.TaskResourceBindingRef(gitResource.Name), - tb.TaskResourceBindingPaths("output-folder"), - ), - ), - tb.TaskRunWorkspaceEmptyDir("bread", "path"), - tb.TaskRunWorkspacePVC("pizza", "", "pool-party"), - ), - tb.TaskRunStatus( - tb.PodName("my-pod-name"), - tb.StatusCondition(apis.Condition{Type: apis.ConditionSucceeded}), - tb.StepState(tb.StateTerminated(127)), - tb.SidecarState( - tb.SidecarStateName("sidecar"), - tb.SidecarStateImageID("ImageID"), - tb.SidecarStateContainerName("ContainerName"), - tb.SetSidecarStateTerminated(terminatedState), - ), - ), - ) - expectedTaskRun := &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun", Namespace: "foo", - OwnerReferences: []metav1.OwnerReference{{ - Name: "test", - Kind: "PipelineRun", - APIVersion: "a1", - Controller: &trueB, - BlockOwnerDeletion: &trueB, - }}, - Labels: map[string]string{ - "label": "label-value", - "label-2": "label-value-2", - "label-3": "label-value-3", - }, - Annotations: map[string]string{ - "annotation-1": "annotation-value-1", - "annotation-2": "annotation-value-2", - }, - }, - Spec: v1alpha1.TaskRunSpec{ - Inputs: &v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskResourceBinding{{ - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: "git-resource", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "my-git", - APIVersion: "a1", - }, - }, - Paths: []string{"source-folder"}, - }, { - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: "another-git-resource", - ResourceSpec: &v1alpha1.PipelineResourceSpec{Type: v1alpha1.PipelineResourceType("cluster")}, - }, - Paths: []string{"source-folder"}, - }}, - Params: []v1alpha1.Param{{ - Name: "iparam", - Value: *tb.ArrayOrString("ivalue"), - }, { - Name: "arrayparam", - Value: *tb.ArrayOrString("array", "values"), - }}, - }, - Outputs: &v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskResourceBinding{{ - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: "git-resource", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "git-resource", - }, - }, - Paths: []string{"output-folder"}, - }}, - }, - Resources: &v1beta1.TaskRunResources{}, - Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, - TaskRef: &v1alpha1.TaskRef{ - Name: "task-output", - Kind: v1alpha1.ClusterTaskKind, - APIVersion: "a1", - }, - Workspaces: []v1alpha1.WorkspaceBinding{{ - Name: "bread", - SubPath: "path", - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }, { - Name: "pizza", - SubPath: "", - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: "pool-party", - }, - }}, - }, - Status: v1alpha1.TaskRunStatus{ - Status: duckv1beta1.Status{ - Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}}, - }, - TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ - PodName: "my-pod-name", - Sidecars: []v1beta1.SidecarState{{ - Name: "sidecar", - ImageID: "ImageID", - ContainerName: "ContainerName", - ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - Reason: "Completed", - }, - }, - }}, - Steps: []v1alpha1.StepState{{ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ExitCode: 127}, - }}}, - }, - }, - } - if d := cmp.Diff(expectedTaskRun, taskRun); d != "" { - t.Fatalf("TaskRun diff -want, +got: %v", d) - } -} - -func TestTaskRunWithTaskSpec(t *testing.T) { - taskRun := tb.TaskRun("test-taskrun", - tb.TaskRunNamespace("foo"), - tb.TaskRunSpec( - tb.TaskRunTaskSpec( - tb.Step("image", tb.StepCommand("/mycmd")), - tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit, tb.ResourceOptional(true))), - ), - tb.TaskRunServiceAccountName("sa"), - tb.TaskRunTimeout(2*time.Minute), - tb.TaskRunSpecStatus(v1alpha1.TaskRunSpecStatusCancelled), - )) - expectedTaskRun := &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun", Namespace: "foo", - Annotations: map[string]string{}, - }, - Spec: v1alpha1.TaskRunSpec{ - TaskSpec: &v1alpha1.TaskSpec{ - TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Image: "image", - Command: []string{"/mycmd"}, - }}}, - }, - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "workspace", - Type: v1alpha1.PipelineResourceTypeGit, - Optional: true, - }}}, - Params: nil, - }, - }, - Resources: &v1beta1.TaskRunResources{}, - ServiceAccountName: "sa", - Status: v1alpha1.TaskRunSpecStatusCancelled, - Timeout: &metav1.Duration{Duration: 2 * time.Minute}, - }, - } - if d := cmp.Diff(expectedTaskRun, taskRun); d != "" { - t.Fatalf("TaskRun diff -want, +got: %v", d) - } -} - -func TestTaskRunWithPodTemplate(t *testing.T) { - taskRun := tb.TaskRun("test-taskrun", - tb.TaskRunNamespace("foo"), - tb.TaskRunSpec( - tb.TaskRunTaskSpec( - tb.Step("image", tb.StepCommand("/mycmd")), - tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit, tb.ResourceOptional(true))), - ), - tb.TaskRunServiceAccountName("sa"), - tb.TaskRunTimeout(2*time.Minute), - tb.TaskRunSpecStatus(v1alpha1.TaskRunSpecStatusCancelled), - tb.TaskRunNodeSelector(map[string]string{ - "label": "value", - }), - )) - expectedTaskRun := &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun", Namespace: "foo", - Annotations: map[string]string{}, - }, - Spec: v1alpha1.TaskRunSpec{ - TaskSpec: &v1alpha1.TaskSpec{ - TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Image: "image", - Command: []string{"/mycmd"}, - }}}, - }, - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "workspace", - Type: v1alpha1.PipelineResourceTypeGit, - Optional: true, - }}}, - Params: nil, - }, - }, - PodTemplate: &v1alpha1.PodTemplate{ - NodeSelector: map[string]string{ - "label": "value", - }, - }, - Resources: &v1beta1.TaskRunResources{}, - ServiceAccountName: "sa", - Status: v1alpha1.TaskRunSpecStatusCancelled, - Timeout: &metav1.Duration{Duration: 2 * time.Minute}, - }, - } - if d := cmp.Diff(expectedTaskRun, taskRun); d != "" { - t.Fatalf("TaskRun diff -want, +got: %v", d) - } -} diff --git a/pkg/apis/pipeline/v1alpha1/condition_defaults_test.go b/pkg/apis/pipeline/v1alpha1/condition_defaults_test.go index 43ae37cf163..eac3b875fcf 100644 --- a/pkg/apis/pipeline/v1alpha1/condition_defaults_test.go +++ b/pkg/apis/pipeline/v1alpha1/condition_defaults_test.go @@ -21,73 +21,75 @@ import ( "testing" "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/test/diff" ) func TestConditionSpec_SetDefaults(t *testing.T) { - cases := []struct { + for _, tc := range []struct { name string input *v1alpha1.ConditionSpec output *v1alpha1.ConditionSpec - }{ - { - name: "No Param", - input: &v1alpha1.ConditionSpec{}, - output: &v1alpha1.ConditionSpec{}, + }{{ + name: "No Param", + input: &v1alpha1.ConditionSpec{}, + output: &v1alpha1.ConditionSpec{}, + }, { + name: "One Param", + input: &v1alpha1.ConditionSpec{ + Params: []v1alpha1.ParamSpec{{ + Name: "test-1", + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, + }, + }}, + }, + output: &v1alpha1.ConditionSpec{ + Params: []v1alpha1.ParamSpec{{ + Name: "test-1", + Type: v1alpha1.ParamTypeArray, + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, + }, + }}, }, - { - name: "One Param", - input: &v1alpha1.ConditionSpec{ - Params: []v1alpha1.ParamSpec{ - { - Name: "test-1", - Default: tb.ArrayOrString("an", "array"), - }, + }, { + name: "Multiple Param", + input: &v1alpha1.ConditionSpec{ + Params: []v1alpha1.ParamSpec{{ + Name: "test-1", + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "string", }, - }, - output: &v1alpha1.ConditionSpec{ - Params: []v1alpha1.ParamSpec{ - { - Name: "test-1", - Type: v1alpha1.ParamTypeArray, - Default: tb.ArrayOrString("an", "array"), - }, + }, { + Name: "test-2", + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, }, - }, + }}, }, - { - name: "Multiple Param", - input: &v1alpha1.ConditionSpec{ - Params: []v1alpha1.ParamSpec{ - { - Name: "test-1", - Default: tb.ArrayOrString("array"), - }, - { - Name: "test-2", - Default: tb.ArrayOrString("an", "array"), - }, + output: &v1alpha1.ConditionSpec{ + Params: []v1alpha1.ParamSpec{{ + Name: "test-1", + Type: v1alpha1.ParamTypeString, + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "string", }, - }, - output: &v1alpha1.ConditionSpec{ - Params: []v1alpha1.ParamSpec{ - { - Name: "test-1", - Type: v1alpha1.ParamTypeString, - Default: tb.ArrayOrString("array"), - }, - { - Name: "test-2", - Type: v1alpha1.ParamTypeArray, - Default: tb.ArrayOrString("an", "array"), - }, + }, { + Name: "test-2", + Type: v1alpha1.ParamTypeArray, + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, }, - }, + }}, }, - } - for _, tc := range cases { + }} { t.Run(tc.name, func(t *testing.T) { ctx := context.Background() tc.input.SetDefaults(ctx) diff --git a/pkg/apis/pipeline/v1alpha1/condition_types_test.go b/pkg/apis/pipeline/v1alpha1/condition_types_test.go index 86a7ac63eaf..840a119aa01 100644 --- a/pkg/apis/pipeline/v1alpha1/condition_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/condition_types_test.go @@ -19,20 +19,21 @@ package v1alpha1_test import ( "testing" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" - - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) func TestConditionCheck_IsDone(t *testing.T) { - tr := tb.TaskRun("", tb.TaskRunStatus(tb.StatusCondition( - apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - }, - ))) + tr := &v1alpha1.TaskRun{ + Status: v1alpha1.TaskRunStatus{Status: duckv1beta1.Status{ + Conditions: []apis.Condition{{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionFalse, + }}, + }}, + } cc := v1alpha1.ConditionCheck(*tr) if !cc.IsDone() { @@ -41,12 +42,14 @@ func TestConditionCheck_IsDone(t *testing.T) { } func TestConditionCheck_IsSuccessful(t *testing.T) { - tr := tb.TaskRun("", tb.TaskRunStatus(tb.StatusCondition( - apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }, - ))) + tr := &v1alpha1.TaskRun{ + Status: v1alpha1.TaskRunStatus{Status: duckv1beta1.Status{ + Conditions: []apis.Condition{{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionTrue, + }}, + }}, + } cc := v1alpha1.ConditionCheck(*tr) if !cc.IsSuccessful() { diff --git a/pkg/apis/pipeline/v1alpha1/condition_validation_test.go b/pkg/apis/pipeline/v1alpha1/condition_validation_test.go index 4b7a5dc7456..2e408010f56 100644 --- a/pkg/apis/pipeline/v1alpha1/condition_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/condition_validation_test.go @@ -22,71 +22,97 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/test/diff" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" ) func TestCondition_Validate(t *testing.T) { - c := tb.Condition("condname", - tb.ConditionSpec( - tb.ConditionSpecCheck("cname", "ubuntu"), - tb.ConditionParamSpec("paramname", v1alpha1.ParamTypeString), - )) - + c := v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{Name: "condname"}, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{Container: corev1.Container{ + Name: "cname", + Image: "ubuntu", + }}, + Params: []v1alpha1.ParamSpec{{ + Name: "paramname", + Type: v1alpha1.ParamTypeString, + }}, + }, + } if err := c.Validate(context.Background()); err != nil { t.Errorf("Condition.Validate() unexpected error = %v", err) } } -func TestCondition_Invalidate(t *testing.T) { - tcs := []struct { +func TestCondition_Invalid(t *testing.T) { + for _, tc := range []struct { name string cond *v1alpha1.Condition expectedError apis.FieldError }{{ name: "invalid meta", - cond: tb.Condition("invalid.,name"), + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{Name: "invalid.,name"}, + }, expectedError: apis.FieldError{ Message: "Invalid resource name: special character . must not be present", Paths: []string{"metadata.name"}, }, }, { name: "no image", - cond: tb.Condition("cond", tb.ConditionSpec( - tb.ConditionSpecCheck("", ""), - )), + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{Name: "condname"}, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{Container: corev1.Container{ + Image: "", + }}, + }, + }, expectedError: apis.FieldError{ Message: "missing field(s)", Paths: []string{"Spec.Check.Image"}, }, }, { name: "condition with script and command", - cond: tb.Condition("cond", - tb.ConditionSpec( - tb.ConditionSpecCheck("cname", "image", tb.Command("exit 0")), - tb.ConditionSpecCheckScript("echo foo"), - )), + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{Name: "condname"}, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Image: "image", + Command: []string{"exit", "0"}, + }, + Script: "echo foo", + }, + }, + }, expectedError: apis.FieldError{ Message: "step 0 script cannot be used with command", Paths: []string{"Spec.Check.script"}, }, }, { name: "condition with invalid check name", - cond: tb.Condition("cond", - tb.ConditionSpec( - tb.ConditionSpecCheck("Cname", "image", tb.Command("exit 0")), - tb.ConditionSpecCheckScript("echo foo"), - )), + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{Name: "condname"}, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Name: "Cname", + Image: "image", + }, + }, + }, + }, expectedError: apis.FieldError{ Message: "invalid value \"Cname\"", Paths: []string{"Spec.Check.name"}, Details: "Condition check name must be a valid DNS Label, For more info refer to https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names", }, - }} - - for _, tc := range tcs { + }} { t.Run(tc.name, func(t *testing.T) { err := tc.cond.Validate(context.Background()) if err == nil { diff --git a/pkg/apis/pipeline/v1alpha1/param_types_test.go b/pkg/apis/pipeline/v1alpha1/param_types_test.go index bc320ef014e..9d1aec7c4dd 100644 --- a/pkg/apis/pipeline/v1alpha1/param_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/param_types_test.go @@ -23,7 +23,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/test/diff" ) @@ -45,13 +44,19 @@ func TestParamSpec_SetDefaults(t *testing.T) { }, { name: "inferred type from default value", before: &v1alpha1.ParamSpec{ - Name: "parametername", - Default: tb.ArrayOrString("an", "array"), + Name: "parametername", + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, + }, }, defaultsApplied: &v1alpha1.ParamSpec{ - Name: "parametername", - Type: v1alpha1.ParamTypeArray, - Default: tb.ArrayOrString("an", "array"), + Name: "parametername", + Type: v1alpha1.ParamTypeArray, + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, + }, }, }, { name: "fully defined ParamSpec", @@ -59,13 +64,19 @@ func TestParamSpec_SetDefaults(t *testing.T) { Name: "parametername", Type: v1alpha1.ParamTypeArray, Description: "a description", - Default: tb.ArrayOrString("an", "array"), + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, + }, }, defaultsApplied: &v1alpha1.ParamSpec{ Name: "parametername", Type: v1alpha1.ParamTypeArray, Description: "a description", - Default: tb.ArrayOrString("an", "array"), + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, + }, }, }} for _, tc := range tests { @@ -92,43 +103,73 @@ func TestArrayOrString_ApplyReplacements(t *testing.T) { }{{ name: "no replacements on array", args: args{ - input: tb.ArrayOrString("an", "array"), + input: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, + }, stringReplacements: map[string]string{"some": "value", "anotherkey": "value"}, arrayReplacements: map[string][]string{"arraykey": {"array", "value"}, "sdfdf": {"sdf", "sdfsd"}}, }, - expectedOutput: tb.ArrayOrString("an", "array"), + expectedOutput: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"an", "array"}, + }, }, { name: "string replacements on string", args: args{ - input: tb.ArrayOrString("astring$(some) asdf $(anotherkey)"), + input: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "astring$(some) asdf $(anotherkey)", + }, stringReplacements: map[string]string{"some": "value", "anotherkey": "value"}, arrayReplacements: map[string][]string{"arraykey": {"array", "value"}, "sdfdf": {"asdf", "sdfsd"}}, }, - expectedOutput: tb.ArrayOrString("astringvalue asdf value"), + expectedOutput: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "astringvalue asdf value", + }, }, { name: "single array replacement", args: args{ - input: tb.ArrayOrString("firstvalue", "$(arraykey)", "lastvalue"), + input: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"firstvalue", "$(arraykey)", "lastvalue"}, + }, stringReplacements: map[string]string{"some": "value", "anotherkey": "value"}, arrayReplacements: map[string][]string{"arraykey": {"array", "value"}, "sdfdf": {"asdf", "sdfsd"}}, }, - expectedOutput: tb.ArrayOrString("firstvalue", "array", "value", "lastvalue"), + expectedOutput: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"firstvalue", "array", "value", "lastvalue"}, + }, }, { name: "multiple array replacement", args: args{ - input: tb.ArrayOrString("firstvalue", "$(arraykey)", "lastvalue", "$(sdfdf)"), + input: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"firstvalue", "$(arraykey)", "lastvalue", "$(sdfdf)"}, + }, stringReplacements: map[string]string{"some": "value", "anotherkey": "value"}, arrayReplacements: map[string][]string{"arraykey": {"array", "value"}, "sdfdf": {"asdf", "sdfsd"}}, }, - expectedOutput: tb.ArrayOrString("firstvalue", "array", "value", "lastvalue", "asdf", "sdfsd"), + expectedOutput: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"firstvalue", "array", "value", "lastvalue", "asdf", "sdfsd"}, + }, }, { name: "empty array replacement", args: args{ - input: tb.ArrayOrString("firstvalue", "$(arraykey)", "lastvalue"), + input: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"firstvalue", "$(arraykey)", "lastvalue"}, + }, stringReplacements: map[string]string{"some": "value", "anotherkey": "value"}, arrayReplacements: map[string][]string{"arraykey": {}}, }, - expectedOutput: tb.ArrayOrString("firstvalue", "lastvalue"), + expectedOutput: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"firstvalue", "lastvalue"}, + }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -145,46 +186,56 @@ type ArrayOrStringHolder struct { } func TestArrayOrString_UnmarshalJSON(t *testing.T) { - cases := []struct { - input string - result v1alpha1.ArrayOrString - }{ - {"{\"val\": \"123\"}", *tb.ArrayOrString("123")}, - {"{\"val\": \"\"}", *tb.ArrayOrString("")}, - {"{\"val\":[]}", v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeArray, ArrayVal: []string{}}}, - {"{\"val\":[\"oneelement\"]}", v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeArray, ArrayVal: []string{"oneelement"}}}, - {"{\"val\":[\"multiple\", \"elements\"]}", v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeArray, ArrayVal: []string{"multiple", "elements"}}}, - } - - for _, c := range cases { - var result ArrayOrStringHolder - if err := json.Unmarshal([]byte(c.input), &result); err != nil { + for _, c := range []struct { + input string + want v1alpha1.ArrayOrString + }{{ + input: "{\"val\": \"123\"}", + want: v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeString, StringVal: "123"}, + }, { + input: "{\"val\": \"\"}", + want: v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeString, StringVal: ""}, + }, { + input: "{\"val\":[]}", + want: v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeArray, ArrayVal: []string{}}, + }, { + input: "{\"val\":[\"oneelement\"]}", + want: v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeArray, ArrayVal: []string{"oneelement"}}, + }, { + input: "{\"val\":[\"multiple\", \"elements\"]}", + want: v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeArray, ArrayVal: []string{"multiple", "elements"}}}, + } { + var got ArrayOrStringHolder + if err := json.Unmarshal([]byte(c.input), &got); err != nil { t.Errorf("Failed to unmarshal input '%v': %v", c.input, err) } - if !reflect.DeepEqual(result.AOrS, c.result) { - t.Errorf("Failed to unmarshal input '%v': expected %+v, got %+v", c.input, c.result, result) + if !reflect.DeepEqual(got.AOrS, c.want) { + t.Errorf("Failed to unmarshal input '%v': expected %+v, got %+v", c.input, c.want, got.AOrS) } } } func TestArrayOrString_MarshalJSON(t *testing.T) { - cases := []struct { - input v1alpha1.ArrayOrString - result string - }{ - {*tb.ArrayOrString("123"), "{\"val\":\"123\"}"}, - {*tb.ArrayOrString("123", "1234"), "{\"val\":[\"123\",\"1234\"]}"}, - {*tb.ArrayOrString("a", "a", "a"), "{\"val\":[\"a\",\"a\",\"a\"]}"}, - } - - for _, c := range cases { + for _, c := range []struct { + input v1alpha1.ArrayOrString + want string + }{{ + input: v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeString, StringVal: "123"}, + want: "{\"val\":\"123\"}", + }, { + input: v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeArray, ArrayVal: []string{"123", "1234"}}, + want: "{\"val\":[\"123\",\"1234\"]}", + }, { + input: v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeArray, ArrayVal: []string{"a", "a", "a"}}, + want: "{\"val\":[\"a\",\"a\",\"a\"]}", + }} { input := ArrayOrStringHolder{c.input} - result, err := json.Marshal(&input) + got, err := json.Marshal(&input) if err != nil { t.Errorf("Failed to marshal input '%v': %v", input, err) } - if string(result) != c.result { - t.Errorf("Failed to marshal input '%v': expected: %+v, got %q", input, c.result, string(result)) + if string(got) != c.want { + t.Errorf("Failed to marshal input '%v': expected: %+v, got %q", input, c.want, string(got)) } } } diff --git a/pkg/apis/pipeline/v1alpha1/pipeline_validation_test.go b/pkg/apis/pipeline/v1alpha1/pipeline_validation_test.go index 1374bcc0b9c..c757737d94a 100644 --- a/pkg/apis/pipeline/v1alpha1/pipeline_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/pipeline_validation_test.go @@ -18,12 +18,14 @@ package v1alpha1_test import ( "context" + "strings" "testing" tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestPipeline_Validate(t *testing.T) { @@ -33,102 +35,181 @@ func TestPipeline_Validate(t *testing.T) { failureExpected bool }{{ name: "valid metadata", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("foo", "foo-task"), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }}, + }, + }, failureExpected: false, }, { name: "period in name", - p: tb.Pipeline("pipe.line", tb.PipelineSpec( - tb.PipelineTask("foo", "foo-task"), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipe.line"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }}, + }, + }, failureExpected: true, }, { name: "pipeline name too long", - p: tb.Pipeline("asdf123456789012345678901234567890123456789012345678901234567890", tb.PipelineSpec( - tb.PipelineTask("foo", "foo-task"), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: strings.Repeat("a", 64)}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }}, + }, + }, failureExpected: true, }, { - name: "pipeline spec missing", - p: tb.Pipeline("pipeline"), + name: "pipeline spec missing", + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + }, failureExpected: true, }, { name: "pipeline spec invalid (duplicate tasks)", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("foo", "foo-task"), - tb.PipelineTask("foo", "foo-task"), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }, { + Name: "foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }}, + }, + }, failureExpected: true, }, { name: "pipeline spec empty task name", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("", "foo-task"), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }}, + }, + }, failureExpected: true, }, { name: "pipeline spec invalid task name", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("_foo", "foo-task"), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "_foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }}, + }, + }, failureExpected: true, }, { - name: "pipeline spec invalid task name 2", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("FooTask", "foo-task"), - )), + name: "pipeline spec invalid task name (capital)", + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "Foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }}, + }, + }, failureExpected: true, }, { name: "pipeline spec invalid taskref name", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("foo", "_foo-task"), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{Name: "_foo-task"}, + }}, + }, + }, failureExpected: true, }, { - name: "pipeline spec missing tasfref and taskspec", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("", ""), - tb.PipelineTask("", "", tb.PipelineTaskSpec(&v1alpha1.TaskSpec{})), - )), + name: "pipeline spec missing taskfref and taskspec", + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + }}, + }, + }, failureExpected: true, }, { name: "pipeline spec with taskref and taskspec", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("foo", "foo-task", tb.PipelineTaskSpec(&v1alpha1.TaskSpec{ - TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "foo", - Image: "bar", - }}}, - }, + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + TaskSpec: &v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{Container: corev1.Container{ + Name: "foo", + Image: "bar", + }}}, + }}, + }}, }, - )))), + }, failureExpected: true, }, { name: "pipeline spec invalid taskspec", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("foo-task", "", tb.PipelineTaskSpec(&v1alpha1.TaskSpec{})), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskSpec: &v1alpha1.TaskSpec{}, + }}, + }, + }, failureExpected: true, }, { name: "pipeline spec valid taskspec", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("foo-task", "", tb.PipelineTaskSpec(&v1alpha1.TaskSpec{ - TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "foo", - Image: "bar", - }}}, - }, + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskSpec: &v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{Container: corev1.Container{ + Name: "foo", + Image: "bar", + }}}, + }}, + }}, }, - )))), + }, failureExpected: false, }, { name: "no duplicate tasks", - p: tb.Pipeline("pipeline", tb.PipelineSpec( - tb.PipelineTask("foo", "foo-task"), - tb.PipelineTask("bar", "bar-task"), - )), + p: &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{Name: "pipeline"}, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{Name: "foo-task"}, + }, { + Name: "bar", + TaskRef: &v1alpha1.TaskRef{Name: "bar-task"}, + }}, + }, + }, failureExpected: false, }, { // Adding this case because `task.Resources` is a pointer, explicitly making sure this is handled diff --git a/pkg/apis/pipeline/v1alpha1/task_validation_test.go b/pkg/apis/pipeline/v1alpha1/task_validation_test.go index dcaa8f7806b..1146960ceb8 100644 --- a/pkg/apis/pipeline/v1alpha1/task_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/task_validation_test.go @@ -22,7 +22,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" @@ -106,7 +105,10 @@ func TestTaskSpecValidate(t *testing.T) { Params: []v1alpha1.ParamSpec{{ Name: "task", Description: "param", - Default: tb.ArrayOrString("default"), + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "default", + }, }}, }, Steps: validSteps, @@ -120,7 +122,10 @@ func TestTaskSpecValidate(t *testing.T) { Name: "task", Type: v1alpha1.ParamTypeString, Description: "param", - Default: tb.ArrayOrString("default"), + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "default", + }, }}, }, Steps: validSteps, @@ -411,12 +416,18 @@ func TestTaskSpecValidateError(t *testing.T) { Name: "validparam", Type: v1alpha1.ParamTypeString, Description: "parameter", - Default: tb.ArrayOrString("default"), + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "default", + }, }, { Name: "param-with-invalid-type", Type: "invalidtype", Description: "invalidtypedesc", - Default: tb.ArrayOrString("default"), + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "default", + }, }}, }, Steps: validSteps, @@ -434,7 +445,10 @@ func TestTaskSpecValidateError(t *testing.T) { Name: "task", Type: v1alpha1.ParamTypeArray, Description: "param", - Default: tb.ArrayOrString("default"), + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "default", + }, }}, }, Steps: validSteps, @@ -452,7 +466,10 @@ func TestTaskSpecValidateError(t *testing.T) { Name: "task", Type: v1alpha1.ParamTypeString, Description: "param", - Default: tb.ArrayOrString("default", "array"), + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeArray, + ArrayVal: []string{"default", "array"}, + }, }}, }, Steps: validSteps, @@ -746,13 +763,14 @@ func TestTaskSpecValidateError(t *testing.T) { name: "Inexistent param variable with existing", fields: fields{ Inputs: &v1alpha1.Inputs{ - Params: []v1alpha1.ParamSpec{ - { - Name: "foo", - Description: "param", - Default: tb.ArrayOrString("default"), + Params: []v1alpha1.ParamSpec{{ + Name: "foo", + Description: "param", + Default: &v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "default", }, - }, + }}, }, Steps: []v1alpha1.Step{{Container: corev1.Container{ Name: "mystep", diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go index 648fdaa7b73..2772ea1462b 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go @@ -217,8 +217,11 @@ func TestTaskRunSpec_Validate(t *testing.T) { func TestInput_Validate(t *testing.T) { i := v1alpha1.TaskRunInputs{ Params: []v1alpha1.Param{{ - Name: "name", - Value: *tb.ArrayOrString("value"), + Name: "name", + Value: v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "value", + }, }}, Resources: []v1alpha1.TaskResourceBinding{{ PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ @@ -271,11 +274,17 @@ func TestInput_Invalid(t *testing.T) { }, }}, Params: []v1alpha1.Param{{ - Name: "name", - Value: *tb.ArrayOrString("value"), + Name: "name", + Value: v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "value", + }, }, { - Name: "name", - Value: *tb.ArrayOrString("value"), + Name: "name", + Value: v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "value", + }, }}, }, wantErr: apis.ErrMultipleOneOf("spec.inputs.params"), diff --git a/test/README.md b/test/README.md index 0940680d7e3..9c3a5543270 100644 --- a/test/README.md +++ b/test/README.md @@ -248,35 +248,6 @@ be used to run only [the unit tests](#unit-tests), i.e.: // +build e2e ``` -#### Create Tekton objects - -To create Tekton objects (e.g. `Task`, `Pipeline`, …), you can use the -[`github.com/tektoncd/pipeline/test/builder`](./builder) package to reduce -noise: - -```go -import tb "github.com/tektoncd/pipeline/test/builder" - -func MyTest(t *testing.T){ - // Pipeline - pipeline := tb.Pipeline("tomatoes", - tb.PipelineSpec(tb.PipelineTask("foo", "banana")), - ) - // … and PipelineRun - pipelineRun := tb.PipelineRun("pear", - tb.PipelineRunSpec("tomatoes", tb.PipelineRunServiceAccount("inexistent")), - ) - // And do something with them - // […] - if _, err := c.PipelineClient.Create(pipeline); err != nil { - t.Fatalf("Failed to create Pipeline `%s`: %s", "tomatoes", err) - } - if _, err := c.PipelineRunClient.Create(pipelineRun); err != nil { - t.Fatalf("Failed to create PipelineRun `%s`: %s", "pear", err) - } -} -``` - #### Get access to client objects To initialize client objects use [the command line flags](#use-flags) which diff --git a/test/builder/README.md b/test/builder/README.md deleted file mode 120000 index be489be009b..00000000000 --- a/test/builder/README.md +++ /dev/null @@ -1 +0,0 @@ -internal/builder/v1alpha1/README.md \ No newline at end of file diff --git a/test/builder/condition.go b/test/builder/condition.go deleted file mode 100644 index 9aaa264e85f..00000000000 --- a/test/builder/condition.go +++ /dev/null @@ -1,72 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" -) - -// ConditionOp is an operation which modifies a Condition struct. -// Deprecated: moved to internal/builder/v1alpha1 -type ConditionOp = v1alpha1.ConditionOp - -// ConditionSpecOp is an operation which modifies a ConditionSpec struct. -// Deprecated: moved to internal/builder/v1alpha1 -type ConditionSpecOp = v1alpha1.ConditionSpecOp - -var ( - - // Condition creates a Condition with default values. - // Any number of Condition modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - Condition = v1alpha1.Condition - - // ConditionNamespace sets the namespace on the condition - // Deprecated: moved to internal/builder/v1alpha1 - ConditionNamespace = v1alpha1.ConditionNamespace - - // ConditionLabels sets the labels on the condition. - // Deprecated: moved to internal/builder/v1alpha1 - ConditionLabels = v1alpha1.ConditionLabels - - // ConditionSpec creates a ConditionSpec with default values. - // Any number of ConditionSpec modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - ConditionSpec = v1alpha1.ConditionSpec - - // ConditionSpecCheck adds a Container, with the specified name and image, to the Condition Spec Check. - // Any number of Container modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - ConditionSpecCheck = v1alpha1.ConditionSpecCheck - - // ConditionDescription sets the description of the condition - // Deprecated: moved to internal/builder/v1alpha1 - ConditionDescription = v1alpha1.ConditionDescription - - // ConditionSpecCheckScript adds a script to the Spec. - // Deprecated: moved to internal/builder/v1alpha1 - ConditionSpecCheckScript = v1alpha1.ConditionSpecCheckScript - - // ConditionParamSpec adds a param, with specified name, to the Spec. - // Any number of ParamSpec modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - ConditionParamSpec = v1alpha1.ConditionParamSpec - - // ConditionResource adds a resource with specified name, and type to the ConditionSpec. - // Deprecated: moved to internal/builder/v1alpha1 - ConditionResource = v1alpha1.ConditionResource -) diff --git a/test/builder/condition_test.go b/test/builder/condition_test.go deleted file mode 100644 index bf184004790..00000000000 --- a/test/builder/condition_test.go +++ /dev/null @@ -1,115 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" -) - -func TestCondition(t *testing.T) { - condition := tb.Condition("cond-name", - tb.ConditionNamespace("foo"), - tb.ConditionLabels( - map[string]string{ - "label-1": "label-value-1", - "label-2": "label-value-2", - }), - tb.ConditionSpec(tb.ConditionSpecCheck("", "ubuntu", tb.Command("exit 0")), - tb.ConditionDescription("Test Condition"), - tb.ConditionParamSpec("param-1", v1alpha1.ParamTypeString, - tb.ParamSpecDefault("default"), - tb.ParamSpecDescription("desc")), - tb.ConditionResource("git-resource", v1alpha1.PipelineResourceTypeGit), - tb.ConditionResource("pr", v1alpha1.PipelineResourceTypePullRequest), - ), - ) - - expected := &v1alpha1.Condition{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cond-name", - Namespace: "foo", - Labels: map[string]string{ - "label-1": "label-value-1", - "label-2": "label-value-2", - }, - }, - Spec: v1alpha1.ConditionSpec{ - Check: v1alpha1.Step{ - Container: corev1.Container{ - Image: "ubuntu", - Command: []string{"exit 0"}, - }, - }, - Description: "Test Condition", - Params: []v1alpha1.ParamSpec{{ - Name: "param-1", - Type: v1alpha1.ParamTypeString, - Description: "desc", - Default: &v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeString, - StringVal: "default", - }}}, - Resources: []v1alpha1.ResourceDeclaration{{ - Name: "git-resource", - Type: "git", - }, { - Name: "pr", - Type: "pullRequest", - }}, - }, - } - - if d := cmp.Diff(expected, condition); d != "" { - t.Fatalf("Condition diff -want, +got: %v", d) - } -} - -func TestConditionWithScript(t *testing.T) { - condition := tb.Condition("cond-name", - tb.ConditionNamespace("foo"), - tb.ConditionSpec(tb.ConditionSpecCheck("", "ubuntu"), - tb.ConditionSpecCheckScript("ls /tmp"), - ), - ) - - expected := &v1alpha1.Condition{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cond-name", - Namespace: "foo", - }, - Spec: v1alpha1.ConditionSpec{ - Check: v1alpha1.Step{ - Container: corev1.Container{ - Image: "ubuntu", - }, - Script: "ls /tmp", - }, - }, - } - - if d := cmp.Diff(expected, condition); d != "" { - t.Fatalf("Condition diff -want, +got: %v", d) - } - -} diff --git a/test/builder/container.go b/test/builder/container.go deleted file mode 100644 index d6766e8907d..00000000000 --- a/test/builder/container.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1beta1 "github.com/tektoncd/pipeline/internal/builder/v1beta1" -) - -// ContainerOp is an operation which modifies a Container struct. -// Deprecated: moved to internal/builder/v1alpha1 -type ContainerOp = v1beta1.ContainerOp - -// VolumeMountOp is an operation which modifies a VolumeMount struct. -// Deprecated: moved to internal/builder/v1alpha1 -type VolumeMountOp = v1beta1.VolumeMountOp - -// ResourceRequirementsOp is an operation which modifies a ResourceRequirements struct. -// Deprecated: moved to internal/builder/v1alpha1 -type ResourceRequirementsOp = v1beta1.ResourceRequirementsOp - -// ResourceListOp is an operation which modifies a ResourceList struct. -// Deprecated: moved to internal/builder/v1alpha1 -type ResourceListOp = v1beta1.ResourceListOp - -var ( - // Command sets the command to the Container (step in this case). - // Deprecated: moved to internal/builder/v1alpha1 - Command = v1beta1.Command - - // Args sets the command arguments to the Container (step in this case). - // Deprecated: moved to internal/builder/v1alpha1 - Args = v1beta1.Args - - // EnvVar add an environment variable, with specified name and value, to the Container (step). - // Deprecated: moved to internal/builder/v1alpha1 - EnvVar = v1beta1.EnvVar - - // WorkingDir sets the WorkingDir on the Container. - // Deprecated: moved to internal/builder/v1alpha1 - WorkingDir = v1beta1.WorkingDir - - // VolumeMount add a VolumeMount to the Container (step). - // Deprecated: moved to internal/builder/v1alpha1 - VolumeMount = v1beta1.VolumeMount - - // Resources adds ResourceRequirements to the Container (step). - // Deprecated: moved to internal/builder/v1alpha1 - Resources = v1beta1.Resources - - // Limits adds Limits to the ResourceRequirements. - // Deprecated: moved to internal/builder/v1alpha1 - Limits = v1beta1.Limits - - // Requests adds Requests to the ResourceRequirements. - // Deprecated: moved to internal/builder/v1alpha1 - Requests = v1beta1.Requests - - // CPU sets the CPU resource on the ResourceList. - // Deprecated: moved to internal/builder/v1alpha1 - CPU = v1beta1.CPU - - // Memory sets the memory resource on the ResourceList. - // Deprecated: moved to internal/builder/v1alpha1 - Memory = v1beta1.Memory - - // EphemeralStorage sets the ephemeral storage resource on the ResourceList. - // Deprecated: moved to internal/builder/v1alpha1 - EphemeralStorage = v1beta1.EphemeralStorage - - // TerminationMessagePath sets the termination message path. - // Deprecated: moved to internal/builder/v1alpha1 - TerminationMessagePath = v1beta1.TerminationMessagePath -) diff --git a/test/builder/doc.go b/test/builder/doc.go deleted file mode 100644 index 968521d635d..00000000000 --- a/test/builder/doc.go +++ /dev/null @@ -1,63 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Package builder holds Builder functions that can be used to create -struct in tests with less noise. - -One of the most important characteristic of a unit test (and any type -of test really) is readability. This means it should be easy to read -but most importantly it should clearly show the intent of the -test. The setup (and cleanup) of the tests should be as small as -possible to avoid the noise. Those builders exists to help with that. - -There is two types of functions defined in that package : - - * Builders: create and return a struct - * Modifiers: return a function - that will operate on a given struct. They can be applied to other - Modifiers or Builders. - -Most of the Builder (and Modifier) that accepts Modifiers defines a -type (`TypeOp`) that can be satisfied by existing function in this -package, from other package *or* inline. An example would be the -following. - - // Definition - type TaskOp func(*v1alpha1.Task) - func Task(name string, ops ...TaskOp) *v1alpha1.Task { - // […] - } - func TaskNamespace(namespace string) TaskOp { - return func(t *v1alpha1.Task) { - // […] - } - } - // Usage - t := Task("foo", TaskNamespace("bar"), func(t *v1alpha1.Task){ - // Do something with the Task struct - // […] - }) - -The main reason to define the `Op` type, and using it in the methods -signatures is to group Modifier function together. It makes it easier -to see what is a Modifier (or Builder) and on what it operates. - -By convention, this package is import with the "tb" as alias. The -examples make that assumption. - -*/ -package builder diff --git a/test/builder/examples_test.go b/test/builder/examples_test.go deleted file mode 100644 index 42928a77db0..00000000000 --- a/test/builder/examples_test.go +++ /dev/null @@ -1,154 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" -) - -// This is a "hack" to make the example "look" like tests -var t *testing.T - -func ExampleTask() { - // You can declare re-usable modifiers - myStep := tb.Step("myimage") - // … and use them in a Task definition - myTask := tb.Task("my-task", tb.TaskSpec( - tb.Step("myotherimage", tb.StepCommand("/mycmd")), - myStep, - )) - // … and another one. - myOtherTask := tb.Task("my-other-task", - tb.TaskSpec(myStep, - tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit)), - ), - ) - expectedTask := &v1alpha1.Task{ - // […] - } - expectedOtherTask := &v1alpha1.Task{ - // […] - } - // […] - if d := cmp.Diff(expectedTask, myTask); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } - if d := cmp.Diff(expectedOtherTask, myOtherTask); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func ExampleClusterTask() { - myClusterTask := tb.ClusterTask("my-task", tb.ClusterTaskSpec( - tb.Step("myotherimage", tb.StepCommand("/mycmd")), - )) - expectedClusterTask := &v1alpha1.Task{ - // […] - } - // […] - if d := cmp.Diff(expectedClusterTask, myClusterTask); d != "" { - t.Fatalf("ClusterTask diff -want, +got: %v", d) - } -} - -func ExampleTaskRun() { - // A simple definition, with a Task reference - myTaskRun := tb.TaskRun("my-taskrun", tb.TaskRunSpec( - tb.TaskRunTaskRef("my-task"), - )) - // … or a more complex one with inline TaskSpec - myTaskRunWithSpec := tb.TaskRun("my-taskrun-with-spec", tb.TaskRunSpec( - tb.TaskRunInputs( - tb.TaskRunInputsParam("myarg", "foo"), - tb.TaskRunInputsResource("workspace", tb.TaskResourceBindingRef("git-resource")), - ), - tb.TaskRunTaskSpec( - tb.TaskInputs( - tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit), - tb.InputsParamSpec("myarg", v1alpha1.ParamTypeString, tb.ParamSpecDefault("mydefault")), - ), - tb.Step("myimage", tb.StepCommand("/mycmd"), - tb.StepArgs("--my-arg=$(inputs.params.myarg)"), - ), - ), - )) - expectedTaskRun := &v1alpha1.TaskRun{ - // […] - } - expectedTaskRunWithSpec := &v1alpha1.TaskRun{ - // […] - } - // […] - if d := cmp.Diff(expectedTaskRun, myTaskRun); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } - if d := cmp.Diff(expectedTaskRunWithSpec, myTaskRunWithSpec); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func ExamplePipeline() { - pipeline := tb.Pipeline("tomatoes", - tb.PipelineSpec(tb.PipelineTask("foo", "banana")), - ) - expectedPipeline := &v1alpha1.Pipeline{ - // […] - } - // […] - if d := cmp.Diff(expectedPipeline, pipeline); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func ExamplePipelineRun() { - pipelineRun := tb.PipelineRun("pear", - tb.PipelineRunSpec("tomatoes", tb.PipelineRunServiceAccountName("inexistent")), - ) - expectedPipelineRun := &v1alpha1.PipelineRun{ - // […] - } - // […] - if d := cmp.Diff(expectedPipelineRun, pipelineRun); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func ExamplePipelineResource() { - gitResource := tb.PipelineResource("git-resource", tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "https://foo.git"), - )) - imageResource := tb.PipelineResource("image-resource", tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeImage, tb.PipelineResourceSpecParam("URL", "gcr.io/kristoff/sven"), - )) - expectedGitResource := v1alpha1.PipelineResource{ - // […] - } - expectedImageResource := v1alpha1.PipelineResource{ - // […] - } - // […] - if d := cmp.Diff(expectedGitResource, gitResource); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } - if d := cmp.Diff(expectedImageResource, imageResource); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} diff --git a/test/builder/owner_reference.go b/test/builder/owner_reference.go deleted file mode 100644 index ed939247880..00000000000 --- a/test/builder/owner_reference.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1beta1 "github.com/tektoncd/pipeline/internal/builder/v1beta1" -) - -// OwnerReferenceOp is an operation which modifies an OwnerReference struct. -// Deprecated: moved to internal/builder/v1alpha1 -type OwnerReferenceOp = v1beta1.OwnerReferenceOp - -var ( - // OwnerReferenceAPIVersion sets the APIVersion to the OwnerReference. - // Deprecated: moved to internal/builder/v1alpha1 - OwnerReferenceAPIVersion = v1beta1.OwnerReferenceAPIVersion - - // Controller sets the Controller to the OwnerReference. - // Deprecated: moved to internal/builder/v1alpha1 - Controller = v1beta1.Controller - - // BlockOwnerDeletion sets the BlockOwnerDeletion to the OwnerReference. - // Deprecated: moved to internal/builder/v1alpha1 - BlockOwnerDeletion = v1beta1.BlockOwnerDeletion -) diff --git a/test/builder/param.go b/test/builder/param.go deleted file mode 100644 index ea0edd79ef1..00000000000 --- a/test/builder/param.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2019 The Tekton Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" -) - -// ParamSpecOp is an operation which modify a ParamSpec struct. -type ParamSpecOp = v1alpha1.ParamSpecOp - -var ( - // ArrayOrString creates an ArrayOrString of type ParamTypeString or ParamTypeArray, based on - // how many inputs are given (>1 input will create an array, not string). - // Deprecated: moved to internal/builder/v1alpha1 - ArrayOrString = v1alpha1.ArrayOrString - - // ParamSpecDescription sets the description of a ParamSpec. - // Deprecated: moved to internal/builder/v1alpha1 - ParamSpecDescription = v1alpha1.ParamSpecDescription - - // ParamSpecDefault sets the default value of a ParamSpec. - // Deprecated: moved to internal/builder/v1alpha1 - ParamSpecDefault = v1alpha1.ParamSpecDefault -) diff --git a/test/builder/param_test.go b/test/builder/param_test.go deleted file mode 100644 index 08aa93b9fca..00000000000 --- a/test/builder/param_test.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright 2019 The Tekton Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" -) - -func TestGenerateString(t *testing.T) { - value := tb.ArrayOrString("somestring") - expectedValue := &v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeString, - StringVal: "somestring", - } - if d := cmp.Diff(expectedValue, value); d != "" { - t.Fatalf("ArrayOrString diff -want, +got: %v", d) - } -} - -func TestGenerateArray(t *testing.T) { - value := tb.ArrayOrString("some", "array", "elements") - expectedValue := &v1alpha1.ArrayOrString{ - Type: v1alpha1.ParamTypeArray, - ArrayVal: []string{"some", "array", "elements"}, - } - if d := cmp.Diff(expectedValue, value); d != "" { - t.Fatalf("ArrayOrString diff -want, +got: %v", d) - } -} diff --git a/test/builder/pipeline.go b/test/builder/pipeline.go deleted file mode 100644 index 8410fe2f4be..00000000000 --- a/test/builder/pipeline.go +++ /dev/null @@ -1,306 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" -) - -// PipelineOp is an operation which modify a Pipeline struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineOp = v1alpha1.PipelineOp - -// PipelineSpecOp is an operation which modify a PipelineSpec struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineSpecOp = v1alpha1.PipelineSpecOp - -// PipelineTaskOp is an operation which modify a PipelineTask struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineTaskOp = v1alpha1.PipelineTaskOp - -// PipelineRunOp is an operation which modify a PipelineRun struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineRunOp = v1alpha1.PipelineRunOp - -// PipelineRunSpecOp is an operation which modify a PipelineRunSpec struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineRunSpecOp = v1alpha1.PipelineRunSpecOp - -// PipelineResourceOp is an operation which modify a PipelineResource struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineResourceOp = v1alpha1.PipelineResourceOp - -// PipelineResourceBindingOp is an operation which modify a PipelineResourceBinding struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineResourceBindingOp = v1alpha1.PipelineResourceBindingOp - -// PipelineResourceSpecOp is an operation which modify a PipelineResourceSpec struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineResourceSpecOp = v1alpha1.PipelineResourceSpecOp - -// PipelineTaskInputResourceOp is an operation which modifies a PipelineTaskInputResource. -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineTaskInputResourceOp = v1alpha1.PipelineTaskInputResourceOp - -// PipelineRunStatusOp is an operation which modifies a PipelineRunStatus -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineRunStatusOp = v1alpha1.PipelineRunStatusOp - -// PipelineTaskConditionOp is an operation which modifies a PipelineTaskCondition -// Deprecated: moved to internal/builder/v1alpha1 -type PipelineTaskConditionOp = v1alpha1.PipelineTaskConditionOp - -var ( - - // Pipeline creates a Pipeline with default values. - // Any number of Pipeline modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - Pipeline = v1alpha1.Pipeline - - // PipelineNamespace sets the namespace on the Pipeline - // Deprecated: moved to internal/builder/v1alpha1 - PipelineNamespace = v1alpha1.PipelineNamespace - - // PipelineSpec sets the PipelineSpec to the Pipeline. - // Any number of PipelineSpec modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineSpec = v1alpha1.PipelineSpec - - // PipelineCreationTimestamp sets the creation time of the pipeline - // Deprecated: moved to internal/builder/v1alpha1 - PipelineCreationTimestamp = v1alpha1.PipelineCreationTimestamp - - // PipelineDescription sets the description of the pipeline - // Deprecated: moved to internal/builder/v1alpha1 - PipelineDescription = v1alpha1.PipelineDescription - - // PipelineRunCancelled sets the status to cancel to the TaskRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunCancelled = v1alpha1.PipelineRunCancelled - - // PipelineDeclaredResource adds a resource declaration to the Pipeline Spec, - // with the specified name and type. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineDeclaredResource = v1alpha1.PipelineDeclaredResource - - // PipelineParamSpec adds a param, with specified name and type, to the PipelineSpec. - // Any number of PipelineParamSpec modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineParamSpec = v1alpha1.PipelineParamSpec - - // PipelineTask adds a PipelineTask, with specified name and task name, to the PipelineSpec. - // Any number of PipelineTask modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTask = v1alpha1.PipelineTask - - // PipelineResult adds a PipelineResult, with specified name, value and description, to the PipelineSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResult = v1alpha1.PipelineResult - - // PipelineRunResult adds a PipelineResultStatus, with specified name, value and description, to the PipelineRunStatusSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunResult = v1alpha1.PipelineRunResult - - // PipelineTaskSpec sets the TaskSpec on a PipelineTask. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskSpec = v1alpha1.PipelineTaskSpec - - // Retries sets the number of retries on a PipelineTask. - // Deprecated: moved to internal/builder/v1alpha1 - Retries = v1alpha1.Retries - - // RunAfter will update the provided Pipeline Task to indicate that it - // should be run after the provided list of Pipeline Task names. - // Deprecated: moved to internal/builder/v1alpha1 - RunAfter = v1alpha1.RunAfter - - // PipelineTaskRefKind sets the TaskKind to the PipelineTaskRef. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskRefKind = v1alpha1.PipelineTaskRefKind - - // PipelineTaskParam adds a ResourceParam, with specified name and value, to the PipelineTask. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskParam = v1alpha1.PipelineTaskParam - - // From will update the provided PipelineTaskInputResource to indicate that it - // should come from tasks. - // Deprecated: moved to internal/builder/v1alpha1 - From = v1alpha1.From - - // PipelineTaskInputResource adds an input resource to the PipelineTask with the specified - // name, pointing at the declared resource. - // Any number of PipelineTaskInputResource modifies can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskInputResource = v1alpha1.PipelineTaskInputResource - - // PipelineTaskOutputResource adds an output resource to the PipelineTask with the specified - // name, pointing at the declared resource. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskOutputResource = v1alpha1.PipelineTaskOutputResource - - // PipelineTaskCondition adds a condition to the PipelineTask with the - // specified conditionRef. Any number of PipelineTaskCondition modifiers can be passed - // to transform it - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskCondition = v1alpha1.PipelineTaskCondition - - // PipelineTaskConditionParam adds a parameter to a PipelineTaskCondition - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskConditionParam = v1alpha1.PipelineTaskConditionParam - - // PipelineTaskConditionResource adds a resource to a PipelineTaskCondition - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskConditionResource = v1alpha1.PipelineTaskConditionResource - - // PipelineTaskWorkspaceBinding adds a workspace with the specified name, workspace and subpath on a PipelineTask. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskWorkspaceBinding = v1alpha1.PipelineTaskWorkspaceBinding - - // PipelineTaskTimeout sets the timeout for the PipelineTask. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineTaskTimeout = v1alpha1.PipelineTaskTimeout - - // PipelineRun creates a PipelineRun with default values. - // Any number of PipelineRun modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRun = v1alpha1.PipelineRun - - // PipelineRunNamespace sets the namespace on a PipelineRun. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunNamespace = v1alpha1.PipelineRunNamespace - - // PipelineRunSpec sets the PipelineRunSpec, references Pipeline with specified name, to the PipelineRun. - // Any number of PipelineRunSpec modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunSpec = v1alpha1.PipelineRunSpec - - // PipelineRunLabel adds a label to the PipelineRun. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunLabel = v1alpha1.PipelineRunLabel - - // PipelineRunAnnotation adds a annotation to the PipelineRun. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunAnnotation = v1alpha1.PipelineRunAnnotation - - // PipelineRunResourceBinding adds bindings from actual instances to a Pipeline's declared resources. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunResourceBinding = v1alpha1.PipelineRunResourceBinding - - // PipelineResourceBindingRef set the ResourceRef name to the Resource called Name. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResourceBindingRef = v1alpha1.PipelineResourceBindingRef - - // PipelineResourceBindingResourceSpec set the PipelineResourceResourceSpec to the PipelineResourceBinding. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResourceBindingResourceSpec = v1alpha1.PipelineResourceBindingResourceSpec - - // PipelineRunServiceAccountName sets the service account to the PipelineRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunServiceAccountName = v1alpha1.PipelineRunServiceAccountName - - // PipelineRunServiceAccountNameTask configures the service account for given Task in PipelineRun. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunServiceAccountNameTask = v1alpha1.PipelineRunServiceAccountNameTask - - // PipelineRunParam add a param, with specified name and value, to the PipelineRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunParam = v1alpha1.PipelineRunParam - - // PipelineRunTimeout sets the timeout to the PipelineRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunTimeout = v1alpha1.PipelineRunTimeout - - // PipelineRunNilTimeout sets the timeout to nil on the PipelineRunSpec - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunNilTimeout = v1alpha1.PipelineRunNilTimeout - - // PipelineRunNodeSelector sets the Node selector to the PipelineRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunNodeSelector = v1alpha1.PipelineRunNodeSelector - - // PipelineRunTolerations sets the Node selector to the PipelineRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunTolerations = v1alpha1.PipelineRunTolerations - - // PipelineRunAffinity sets the affinity to the PipelineRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunAffinity = v1alpha1.PipelineRunAffinity - - // PipelineRunPipelineSpec adds a PipelineSpec to the PipelineRunSpec. - // Any number of PipelineSpec modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunPipelineSpec = v1alpha1.PipelineRunPipelineSpec - - // PipelineRunStatus sets the PipelineRunStatus to the PipelineRun. - // Any number of PipelineRunStatus modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunStatus = v1alpha1.PipelineRunStatus - - // PipelineRunStatusCondition adds a StatusCondition to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunStatusCondition = v1alpha1.PipelineRunStatusCondition - - // PipelineRunStartTime sets the start time to the PipelineRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunStartTime = v1alpha1.PipelineRunStartTime - - // PipelineRunCompletionTime sets the completion time to the PipelineRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunCompletionTime = v1alpha1.PipelineRunCompletionTime - - // PipelineRunTaskRunsStatus sets the status of TaskRun to the PipelineRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunTaskRunsStatus = v1alpha1.PipelineRunTaskRunsStatus - - // PipelineResource creates a PipelineResource with default values. - // Any number of PipelineResource modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResource = v1alpha1.PipelineResource - - // PipelineResourceNamespace sets the namespace on a PipelineResource. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResourceNamespace = v1alpha1.PipelineResourceNamespace - - // PipelineResourceSpec set the PipelineResourceSpec, with specified type, to the PipelineResource. - // Any number of PipelineResourceSpec modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResourceSpec = v1alpha1.PipelineResourceSpec - - // PipelineResourceDescription sets the description of the pipeline resource - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResourceDescription = v1alpha1.PipelineResourceDescription - - // PipelineResourceSpecParam adds a ResourceParam, with specified name and value, to the PipelineResourceSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResourceSpecParam = v1alpha1.PipelineResourceSpecParam - - // PipelineResourceSpecSecretParam adds a SecretParam, with specified fieldname, secretKey and secretName, to the PipelineResourceSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineResourceSpecSecretParam = v1alpha1.PipelineResourceSpecSecretParam - - // PipelineWorkspaceDeclaration adds a Workspace to the workspaces listed in the pipeline spec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineWorkspaceDeclaration = v1alpha1.PipelineWorkspaceDeclaration - - // PipelineRunWorkspaceBindingEmptyDir adds an EmptyDir Workspace to the workspaces of a pipelinerun spec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunWorkspaceBindingEmptyDir = v1alpha1.PipelineRunWorkspaceBindingEmptyDir - - // PipelineRunWorkspaceBindingVolumeClaimTemplate adds an VolumeClaimTemplate Workspace to the workspaces of a pipelineRun spec. - // Deprecated: moved to internal/builder/v1alpha1 - PipelineRunWorkspaceBindingVolumeClaimTemplate = v1alpha1.PipelineRunWorkspaceBindingVolumeClaimTemplate -) diff --git a/test/builder/pipeline_test.go b/test/builder/pipeline_test.go deleted file mode 100644 index 8227fc7bba0..00000000000 --- a/test/builder/pipeline_test.go +++ /dev/null @@ -1,415 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - "time" - - "github.com/google/go-cmp/cmp" - 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" - - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" -) - -func TestPipeline(t *testing.T) { - creationTime := time.Now() - - pipeline := tb.Pipeline("tomatoes", tb.PipelineNamespace("foo"), tb.PipelineSpec( - tb.PipelineDeclaredResource("my-only-git-resource", "git"), - tb.PipelineDeclaredResource("my-only-image-resource", "image"), - tb.PipelineDescription("Test Pipeline"), - tb.PipelineParamSpec("first-param", v1alpha1.ParamTypeString, tb.ParamSpecDefault("default-value"), tb.ParamSpecDescription("default description")), - tb.PipelineTask("foo", "banana", - tb.PipelineTaskParam("stringparam", "value"), - tb.PipelineTaskParam("arrayparam", "array", "value"), - tb.PipelineTaskCondition("some-condition-ref", - tb.PipelineTaskConditionParam("param-name", "param-value"), - tb.PipelineTaskConditionResource("some-resource", "my-only-git-resource", "bar", "never-gonna"), - ), - tb.PipelineTaskWorkspaceBinding("task-workspace1", "workspace1", ""), - ), - tb.PipelineTask("bar", "chocolate", - tb.PipelineTaskRefKind(v1alpha1.ClusterTaskKind), - tb.PipelineTaskInputResource("some-repo", "my-only-git-resource", tb.From("foo")), - tb.PipelineTaskOutputResource("some-image", "my-only-image-resource"), - ), - tb.PipelineTask("never-gonna", "give-you-up", - tb.RunAfter("foo"), - tb.PipelineTaskTimeout(5*time.Second), - ), - tb.PipelineTask("foo", "", tb.PipelineTaskSpec(&v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "step", - Image: "myimage", - }}}, - }}, - )), - tb.PipelineWorkspaceDeclaration("workspace1"), - ), - tb.PipelineCreationTimestamp(creationTime), - ) - expectedPipeline := &v1alpha1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{ - Name: "tomatoes", Namespace: "foo", - CreationTimestamp: metav1.Time{Time: creationTime}, - }, - Spec: v1alpha1.PipelineSpec{ - Resources: []v1alpha1.PipelineDeclaredResource{{ - Name: "my-only-git-resource", - Type: "git", - }, { - Name: "my-only-image-resource", - Type: "image", - }}, - Description: "Test Pipeline", - Params: []v1alpha1.ParamSpec{{ - Name: "first-param", - Type: v1alpha1.ParamTypeString, - Default: tb.ArrayOrString("default-value"), - Description: "default description", - }}, - Tasks: []v1alpha1.PipelineTask{{ - Name: "foo", - TaskRef: &v1alpha1.TaskRef{Name: "banana"}, - Params: []v1alpha1.Param{{ - Name: "stringparam", - Value: *tb.ArrayOrString("value"), - }, { - Name: "arrayparam", - Value: *tb.ArrayOrString("array", "value"), - }}, - Conditions: []v1alpha1.PipelineTaskCondition{{ - ConditionRef: "some-condition-ref", - Params: []v1alpha1.Param{{ - Name: "param-name", - Value: v1alpha1.ArrayOrString{ - Type: "string", - StringVal: "param-value", - }, - }}, - Resources: []v1alpha1.PipelineTaskInputResource{{ - Name: "some-resource", - Resource: "my-only-git-resource", - From: []string{"bar", "never-gonna"}, - }}, - }}, - Workspaces: []v1alpha1.WorkspacePipelineTaskBinding{{ - Name: "task-workspace1", - Workspace: "workspace1", - }}, - }, { - Name: "bar", - TaskRef: &v1alpha1.TaskRef{Name: "chocolate", Kind: v1alpha1.ClusterTaskKind}, - Resources: &v1alpha1.PipelineTaskResources{ - Inputs: []v1alpha1.PipelineTaskInputResource{{ - Name: "some-repo", - Resource: "my-only-git-resource", - From: []string{"foo"}, - }}, - Outputs: []v1alpha1.PipelineTaskOutputResource{{ - Name: "some-image", - Resource: "my-only-image-resource", - }}, - }, - }, { - Name: "never-gonna", - TaskRef: &v1alpha1.TaskRef{Name: "give-you-up"}, - RunAfter: []string{"foo"}, - Timeout: &metav1.Duration{Duration: 5 * time.Second}, - }, { - Name: "foo", - TaskSpec: &v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "step", - Image: "myimage", - }}}, - }}, - }}, - Workspaces: []v1alpha1.PipelineWorkspaceDeclaration{{ - Name: "workspace1", - }}, - }, - } - if d := cmp.Diff(expectedPipeline, pipeline); d != "" { - t.Fatalf("Pipeline diff -want, +got: %v", d) - } -} - -func TestPipelineRun(t *testing.T) { - startTime := time.Now() - completedTime := startTime.Add(5 * time.Minute) - - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec( - "tomatoes", tb.PipelineRunServiceAccountName("sa"), - tb.PipelineRunParam("first-param-string", "first-value"), - tb.PipelineRunParam("second-param-array", "some", "array"), - tb.PipelineRunTimeout(1*time.Hour), - tb.PipelineRunResourceBinding("some-resource", tb.PipelineResourceBindingRef("my-special-resource")), - tb.PipelineRunServiceAccountNameTask("foo", "sa-2"), - ), tb.PipelineRunStatus(tb.PipelineRunStatusCondition( - apis.Condition{Type: apis.ConditionSucceeded}), - tb.PipelineRunStartTime(startTime), - tb.PipelineRunCompletionTime(completedTime), - tb.PipelineRunTaskRunsStatus("trname", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "task-1", - }), - ), tb.PipelineRunLabel("label-key", "label-value")) - expectedPipelineRun := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pear", - Namespace: "foo", - Labels: map[string]string{ - "label-key": "label-value", - }, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{Name: "tomatoes"}, - ServiceAccountName: "sa", - ServiceAccountNames: []v1alpha1.PipelineRunSpecServiceAccountName{{TaskName: "foo", ServiceAccountName: "sa-2"}}, - Params: []v1alpha1.Param{{ - Name: "first-param-string", - Value: *tb.ArrayOrString("first-value"), - }, { - Name: "second-param-array", - Value: *tb.ArrayOrString("some", "array"), - }}, - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - Resources: []v1alpha1.PipelineResourceBinding{{ - Name: "some-resource", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "my-special-resource", - }, - }}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}}, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: startTime}, - CompletionTime: &metav1.Time{Time: completedTime}, - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ - "trname": {PipelineTaskName: "task-1"}, - }, - }, - }, - } - if d := cmp.Diff(expectedPipelineRun, pipelineRun); d != "" { - t.Fatalf("PipelineRun diff -want, +got: %v", d) - } -} - -func TestPipelineRunWithPodTemplate(t *testing.T) { - startTime := time.Now() - completedTime := startTime.Add(5 * time.Minute) - - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec( - "tomatoes", tb.PipelineRunServiceAccountName("sa"), - tb.PipelineRunParam("first-param-string", "first-value"), - tb.PipelineRunParam("second-param-array", "some", "array"), - tb.PipelineRunTimeout(1*time.Hour), - tb.PipelineRunResourceBinding("some-resource", tb.PipelineResourceBindingRef("my-special-resource")), - tb.PipelineRunServiceAccountNameTask("foo", "sa-2"), - tb.PipelineRunNodeSelector(map[string]string{ - "label": "value", - }), - ), tb.PipelineRunStatus(tb.PipelineRunStatusCondition( - apis.Condition{Type: apis.ConditionSucceeded}), - tb.PipelineRunStartTime(startTime), - tb.PipelineRunCompletionTime(completedTime), - tb.PipelineRunTaskRunsStatus("trname", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "task-1", - }), - ), tb.PipelineRunLabel("label-key", "label-value")) - expectedPipelineRun := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pear", - Namespace: "foo", - Labels: map[string]string{ - "label-key": "label-value", - }, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{Name: "tomatoes"}, - ServiceAccountName: "sa", - ServiceAccountNames: []v1alpha1.PipelineRunSpecServiceAccountName{{TaskName: "foo", ServiceAccountName: "sa-2"}}, - Params: []v1alpha1.Param{{ - Name: "first-param-string", - Value: *tb.ArrayOrString("first-value"), - }, { - Name: "second-param-array", - Value: *tb.ArrayOrString("some", "array"), - }}, - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - Resources: []v1alpha1.PipelineResourceBinding{{ - Name: "some-resource", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "my-special-resource", - }, - }}, - PodTemplate: &v1alpha1.PodTemplate{ - NodeSelector: map[string]string{ - "label": "value", - }, - }, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}}, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: startTime}, - CompletionTime: &metav1.Time{Time: completedTime}, - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ - "trname": {PipelineTaskName: "task-1"}, - }, - }, - }, - } - if d := cmp.Diff(expectedPipelineRun, pipelineRun); d != "" { - t.Fatalf("PipelineRun diff -want, +got: %v", d) - } -} - -func TestPipelineRunWithResourceSpec(t *testing.T) { - startTime := time.Now() - completedTime := startTime.Add(5 * time.Minute) - - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec( - "tomatoes", tb.PipelineRunServiceAccountName("sa"), - tb.PipelineRunParam("first-param-string", "first-value"), - tb.PipelineRunParam("second-param-array", "some", "array"), - tb.PipelineRunTimeout(1*time.Hour), - tb.PipelineRunResourceBinding("some-resource", - tb.PipelineResourceBindingResourceSpec(&v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.ResourceParam{{ - Name: "url", - Value: "git", - }}})), - tb.PipelineRunServiceAccountNameTask("foo", "sa-2"), - ), tb.PipelineRunStatus(tb.PipelineRunStatusCondition( - apis.Condition{Type: apis.ConditionSucceeded}), - tb.PipelineRunStartTime(startTime), - tb.PipelineRunCompletionTime(completedTime), - tb.PipelineRunTaskRunsStatus("trname", &v1alpha1.PipelineRunTaskRunStatus{ - PipelineTaskName: "task-1", - }), - ), tb.PipelineRunLabel("label-key", "label-value")) - expectedPipelineRun := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pear", - Namespace: "foo", - Labels: map[string]string{ - "label-key": "label-value", - }, - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: &v1alpha1.PipelineRef{Name: "tomatoes"}, - ServiceAccountName: "sa", - ServiceAccountNames: []v1alpha1.PipelineRunSpecServiceAccountName{{TaskName: "foo", ServiceAccountName: "sa-2"}}, - Params: []v1alpha1.Param{{ - Name: "first-param-string", - Value: *tb.ArrayOrString("first-value"), - }, { - Name: "second-param-array", - Value: *tb.ArrayOrString("some", "array"), - }}, - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - Resources: []v1alpha1.PipelineResourceBinding{{ - Name: "some-resource", - ResourceSpec: &v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceType("git"), - Params: []v1alpha1.ResourceParam{{ - Name: "url", - Value: "git", - }}, - SecretParams: nil, - }, - }}, - }, - Status: v1alpha1.PipelineRunStatus{ - Status: duckv1beta1.Status{ - Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}}, - }, - PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ - StartTime: &metav1.Time{Time: startTime}, - CompletionTime: &metav1.Time{Time: completedTime}, - TaskRuns: map[string]*v1alpha1.PipelineRunTaskRunStatus{ - "trname": {PipelineTaskName: "task-1"}, - }, - }, - }, - } - if d := cmp.Diff(expectedPipelineRun, pipelineRun); d != "" { - t.Fatalf("PipelineRun diff -want, +got: %v", d) - } -} - -func TestPipelineRunWithPipelineSpec(t *testing.T) { - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec("", tb.PipelineRunPipelineSpec( - tb.PipelineTask("a-task", "some-task")), - tb.PipelineRunServiceAccountName("sa"), - )) - - expectedPipelineRun := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pear", - Namespace: "foo", - }, - Spec: v1alpha1.PipelineRunSpec{ - PipelineRef: nil, - PipelineSpec: &v1alpha1.PipelineSpec{ - Tasks: []v1alpha1.PipelineTask{{ - Name: "a-task", - TaskRef: &v1alpha1.TaskRef{Name: "some-task"}, - }}, - }, - ServiceAccountName: "sa", - Timeout: &metav1.Duration{Duration: 1 * time.Hour}, - }, - } - - if diff := cmp.Diff(expectedPipelineRun, pipelineRun); diff != "" { - t.Fatalf("PipelineRun diff -want, +got: %s", diff) - } -} - -func TestPipelineResource(t *testing.T) { - pipelineResource := tb.PipelineResource("git-resource", tb.PipelineResourceNamespace("foo"), tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "https://foo.git"), tb.PipelineResourceDescription("test description"), - )) - expectedPipelineResource := &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{Name: "git-resource", Namespace: "foo"}, - Spec: v1alpha1.PipelineResourceSpec{ - Description: "test description", - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.ResourceParam{{ - Name: "URL", Value: "https://foo.git", - }}, - }, - } - if d := cmp.Diff(expectedPipelineResource, pipelineResource); d != "" { - t.Fatalf("PipelineResource diff -want, +got: %v", d) - } -} diff --git a/test/builder/pod.go b/test/builder/pod.go deleted file mode 100644 index 772bb781bc8..00000000000 --- a/test/builder/pod.go +++ /dev/null @@ -1,96 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1beta1 "github.com/tektoncd/pipeline/internal/builder/v1beta1" -) - -// PodOp is an operation which modifies a Pod struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PodOp = v1beta1.PodOp - -// PodSpecOp is an operation which modifies a PodSpec struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PodSpecOp = v1beta1.PodSpecOp - -// PodStatusOp is an operation which modifies a PodStatus struct. -// Deprecated: moved to internal/builder/v1alpha1 -type PodStatusOp = v1beta1.PodStatusOp - -var ( - // Pod creates a Pod with default values. - // Any number of Pod modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - Pod = v1beta1.Pod - - // PodNamespace sets the namespace on the Pod. - // Deprecated: moved to internal/builder/v1alpha1 - PodNamespace = v1beta1.PodNamespace - - // PodAnnotation adds an annotation to the Pod. - // Deprecated: moved to internal/builder/v1alpha1 - PodAnnotation = v1beta1.PodAnnotation - - // PodLabel adds a label to the Pod. - // Deprecated: moved to internal/builder/v1alpha1 - PodLabel = v1beta1.PodLabel - - // PodOwnerReference adds an OwnerReference, with specified kind and name, to the Pod. - // Deprecated: moved to internal/builder/v1alpha1 - PodOwnerReference = v1beta1.PodOwnerReference - - // PodSpec creates a PodSpec with default values. - // Any number of PodSpec modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PodSpec = v1beta1.PodSpec - - // PodRestartPolicy sets the restart policy on the PodSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PodRestartPolicy = v1beta1.PodRestartPolicy - - // PodServiceAccountName sets the service account on the PodSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PodServiceAccountName = v1beta1.PodServiceAccountName - - // PodContainer adds a Container, with the specified name and image, to the PodSpec. - // Any number of Container modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PodContainer = v1beta1.PodContainer - - // PodInitContainer adds an InitContainer, with the specified name and image, to the PodSpec. - // Any number of Container modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PodInitContainer = v1beta1.PodInitContainer - - // PodVolumes sets the Volumes on the PodSpec. - // Deprecated: moved to internal/builder/v1alpha1 - PodVolumes = v1beta1.PodVolumes - - // PodCreationTimestamp sets the creation time of the pod - // Deprecated: moved to internal/builder/v1alpha1 - PodCreationTimestamp = v1beta1.PodCreationTimestamp - - // PodStatus creates a PodStatus with default values. - // Any number of PodStatus modifiers can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - PodStatus = v1beta1.PodStatus - - // PodStatusConditions adds a Conditions (set) to the Pod status. - // Deprecated: moved to internal/builder/v1alpha1 - PodStatusConditions = v1beta1.PodStatusConditions -) diff --git a/test/builder/pod_test.go b/test/builder/pod_test.go deleted file mode 100644 index aaa4b875eb4..00000000000 --- a/test/builder/pod_test.go +++ /dev/null @@ -1,128 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestPod(t *testing.T) { - trueB := true - resourceQuantityCmp := cmp.Comparer(func(x, y resource.Quantity) bool { - return x.Cmp(y) == 0 - }) - volume := corev1.Volume{ - Name: "tools-volume", - VolumeSource: corev1.VolumeSource{}, - } - got := tb.Pod("foo-pod-123456", - tb.PodNamespace("foo"), - tb.PodAnnotation("annotation", "annotation-value"), - tb.PodLabel("label", "label-value"), - tb.PodOwnerReference("TaskRun", "taskrun-foo", - tb.OwnerReferenceAPIVersion("a1")), - tb.PodSpec( - tb.PodServiceAccountName("sa"), - tb.PodRestartPolicy(corev1.RestartPolicyNever), - tb.PodContainer("nop", "nop:latest"), - tb.PodInitContainer("basic", "ubuntu", - tb.Command("ls", "-l"), - tb.Args(), - tb.WorkingDir("/workspace"), - tb.EnvVar("HOME", "/tekton/home"), - tb.VolumeMount("tools-volume", "/tools"), - tb.Resources( - tb.Limits(tb.Memory("1.5Gi")), - tb.Requests( - tb.CPU("100m"), - tb.Memory("1Gi"), - tb.EphemeralStorage("500Mi"), - ), - ), - ), - tb.PodVolumes(volume), - ), - ) - want := &corev1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "foo", - Name: "foo-pod-123456", - Annotations: map[string]string{ - "annotation": "annotation-value", - }, - Labels: map[string]string{ - "label": "label-value", - }, - OwnerReferences: []metav1.OwnerReference{{ - Kind: "TaskRun", - Name: "taskrun-foo", - APIVersion: "a1", - Controller: &trueB, - BlockOwnerDeletion: &trueB, - }}, - }, - Spec: corev1.PodSpec{ - ServiceAccountName: "sa", - RestartPolicy: corev1.RestartPolicyNever, - Containers: []corev1.Container{{ - Name: "nop", - Image: "nop:latest", - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("0"), - corev1.ResourceMemory: resource.MustParse("0"), - corev1.ResourceEphemeralStorage: resource.MustParse("0"), - }, - }, - }}, - InitContainers: []corev1.Container{{ - Name: "basic", - Image: "ubuntu", - Command: []string{"ls", "-l"}, - WorkingDir: "/workspace", - Env: []corev1.EnvVar{{ - Name: "HOME", - Value: "/tekton/home", - }}, - VolumeMounts: []corev1.VolumeMount{{ - Name: "tools-volume", - MountPath: "/tools", - }}, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse("1.5Gi"), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("100m"), - corev1.ResourceMemory: resource.MustParse("1Gi"), - corev1.ResourceEphemeralStorage: resource.MustParse("500Mi"), - }, - }, - }}, - Volumes: []corev1.Volume{volume}, - }, - } - if d := cmp.Diff(want, got, resourceQuantityCmp); d != "" { - t.Fatalf("Pod diff -want, +got: %v", d) - } -} diff --git a/test/builder/sidecar.go b/test/builder/sidecar.go deleted file mode 100644 index 5148ab53b9c..00000000000 --- a/test/builder/sidecar.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright 2020 The Tekton Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" -) - -var ( - // SidecarStateName sets the name of the Sidecar for the SidecarState. - // Deprecated: moved to internal/builder/v1alpha1 - SidecarStateName = v1alpha1.SidecarStateName - - // SidecarStateImageID sets ImageID of Sidecar for SidecarState. - // Deprecated: moved to internal/builder/v1alpha1 - SidecarStateImageID = v1alpha1.SidecarStateImageID - - // SidecarStateContainerName sets ContainerName of Sidecar for SidecarState. - // Deprecated: moved to internal/builder/v1alpha1 - SidecarStateContainerName = v1alpha1.SidecarStateContainerName - - // SetSidecarStateTerminated sets Terminated state of a Sidecar. - // Deprecated: moved to internal/builder/v1alpha1 - SetSidecarStateTerminated = v1alpha1.SetSidecarStateTerminated - - // SetSidecarStateRunning sets Running state of a Sidecar. - // Deprecated: moved to internal/builder/v1alpha1 - SetSidecarStateRunning = v1alpha1.SetSidecarStateRunning - - // SetSidecarStateWaiting sets Waiting state of a Sidecar. - // Deprecated: moved to internal/builder/v1alpha1 - SetSidecarStateWaiting = v1alpha1.SetSidecarStateWaiting -) diff --git a/test/builder/step.go b/test/builder/step.go deleted file mode 100644 index b97e9fa2b1d..00000000000 --- a/test/builder/step.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2019 The Tekton Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" -) - -// StepOp is an operation which modifies a Container struct. -// Deprecated: moved to internal/builder/v1alpha1 -type StepOp = v1alpha1.StepOp - -var ( - // StepName sets the name of the step. - // Deprecated: moved to internal/builder/v1alpha1 - StepName = v1alpha1.StepName - - // StepCommand sets the command to the Container (step in this case). - // Deprecated: moved to internal/builder/v1alpha1 - StepCommand = v1alpha1.StepCommand - - // StepSecurityContext sets the SecurityContext to the Step. - // Deprecated: moved to internal/builder/v1alpha1 - StepSecurityContext = v1alpha1.StepSecurityContext - - // StepArgs sets the command arguments to the Container (step in this case). - // Deprecated: moved to internal/builder/v1alpha1 - StepArgs = v1alpha1.StepArgs - - // StepEnvVar add an environment variable, with specified name and value, to the Container (step). - // Deprecated: moved to internal/builder/v1alpha1 - StepEnvVar = v1alpha1.StepEnvVar - - // StepWorkingDir sets the WorkingDir on the Container. - // Deprecated: moved to internal/builder/v1alpha1 - StepWorkingDir = v1alpha1.StepWorkingDir - - // StepVolumeMount add a VolumeMount to the Container (step). - // Deprecated: moved to internal/builder/v1alpha1 - StepVolumeMount = v1alpha1.StepVolumeMount - - // StepScript sets the script to the Step. - // Deprecated: moved to internal/builder/v1alpha1 - StepScript = v1alpha1.StepScript - - // StepResources adds ResourceRequirements to the Container (step). - // Deprecated: moved to internal/builder/v1alpha1 - StepResources = v1alpha1.StepResources - - // StepLimits adds Limits to the ResourceRequirements. - // Deprecated: moved to internal/builder/v1alpha1 - StepLimits = v1alpha1.StepLimits - - // StepRequests adds Requests to the ResourceRequirements. - // Deprecated: moved to internal/builder/v1alpha1 - StepRequests = v1alpha1.StepRequests - - // StepCPU sets the CPU resource on the ResourceList. - // Deprecated: moved to internal/builder/v1alpha1 - StepCPU = v1alpha1.StepCPU - - // StepMemory sets the memory resource on the ResourceList. - // Deprecated: moved to internal/builder/v1alpha1 - StepMemory = v1alpha1.StepMemory - - // StepEphemeralStorage sets the ephemeral storage resource on the ResourceList. - // Deprecated: moved to internal/builder/v1alpha1 - StepEphemeralStorage = v1alpha1.StepEphemeralStorage - - // StepTerminationMessagePath sets the source of the termination message. - // Deprecated: moved to internal/builder/v1alpha1 - StepTerminationMessagePath = v1alpha1.StepTerminationMessagePath -) diff --git a/test/builder/task.go b/test/builder/task.go deleted file mode 100644 index 0fc21186fb0..00000000000 --- a/test/builder/task.go +++ /dev/null @@ -1,432 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" -) - -// TaskOp is an operation which modify a Task struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskOp = v1alpha1.TaskOp - -// ClusterTaskOp is an operation which modify a ClusterTask struct. -// Deprecated: moved to internal/builder/v1alpha1 -type ClusterTaskOp = v1alpha1.ClusterTaskOp - -// TaskSpecOp is an operation which modify a TaskSpec struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskSpecOp = v1alpha1.TaskSpecOp - -// TaskResourcesOp is an operation which modify a TaskResources struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskResourcesOp = v1alpha1.TaskResourcesOp - -// InputsOp is an operation which modify an Inputs struct. -// Deprecated: moved to internal/builder/v1alpha1 -type InputsOp = v1alpha1.InputsOp - -// OutputsOp is an operation which modify an Outputs struct. -// Deprecated: moved to internal/builder/v1alpha1 -type OutputsOp = v1alpha1.OutputsOp - -// TaskRunOp is an operation which modify a TaskRun struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskRunOp = v1alpha1.TaskRunOp - -// TaskRunSpecOp is an operation which modify a TaskRunSpec struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskRunSpecOp = v1alpha1.TaskRunSpecOp - -// TaskRunResourcesOp is an operation which modify a TaskRunResources struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskRunResourcesOp = v1alpha1.TaskRunResourcesOp - -// TaskResourceOp is an operation which modify a TaskResource struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskResourceOp = v1alpha1.TaskResourceOp - -// TaskResourceBindingOp is an operation which modify a TaskResourceBinding struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskResourceBindingOp = v1alpha1.TaskResourceBindingOp - -// TaskRunStatusOp is an operation which modify a TaskRunStatus struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskRunStatusOp = v1alpha1.TaskRunStatusOp - -// TaskRefOp is an operation which modify a TaskRef struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskRefOp = v1alpha1.TaskRefOp - -// TaskResultOp is an operation which modifies there -// Deprecated: moved to internal/builder/v1alpha1 -type TaskResultOp = v1alpha1.TaskResultOp - -// TaskRunInputsOp is an operation which modify a TaskRunInputs struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskRunInputsOp = v1alpha1.TaskRunInputsOp - -// TaskRunOutputsOp is an operation which modify a TaskRunOutputs struct. -// Deprecated: moved to internal/builder/v1alpha1 -type TaskRunOutputsOp = v1alpha1.TaskRunOutputsOp - -// StepStateOp is an operation which modifies a StepState struct. -// Deprecated: moved to internal/builder/v1alpha1 -type StepStateOp = v1alpha1.StepStateOp - -// SidecarStateOp is an operation which modifies a SidecarState struct. -// Deprecated: moved to internal/builder/v1alpha1 -type SidecarStateOp = v1alpha1.SidecarStateOp - -// VolumeOp is an operation which modify a Volume struct. -// Deprecated: moved to internal/builder/v1alpha1 -type VolumeOp = v1alpha1.VolumeOp - -var ( - - // Task creates a Task with default values. - // Any number of Task modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - Task = v1alpha1.Task - - // TaskType sets the TypeMeta on the Task which is useful for making it serializable/deserializable. - // Deprecated: moved to internal/builder/v1alpha1 - TaskType = v1alpha1.TaskType - - // ClusterTask creates a ClusterTask with default values. - // Any number of ClusterTask modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - ClusterTask = v1alpha1.ClusterTask - - // TaskNamespace sets the namespace on the task. - // Deprecated: moved to internal/builder/v1alpha1 - TaskNamespace = v1alpha1.TaskNamespace - - // ClusterTaskType sets the TypeMeta on the ClusterTask which is useful for making it serializable/deserializable. - // Deprecated: moved to internal/builder/v1alpha1 - ClusterTaskType = v1alpha1.ClusterTaskType - - // ClusterTaskSpec sets the specified spec of the cluster task. - // Any number of TaskSpec modifier can be passed to create it. - // Deprecated: moved to internal/builder/v1alpha1 - ClusterTaskSpec = v1alpha1.ClusterTaskSpec - - // TaskSpec sets the specified spec of the task. - // Any number of TaskSpec modifier can be passed to create/modify it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskSpec = v1alpha1.TaskSpec - - // TaskDescription sets the description of the task - // Deprecated: moved to internal/builder/v1alpha1 - TaskDescription = v1alpha1.TaskDescription - - // Step adds a step with the specified name and image to the TaskSpec. - // Any number of Container modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - Step = v1alpha1.Step - - // Sidecar adds a sidecar container with the specified name and image to the TaskSpec. - // Any number of Container modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - Sidecar = v1alpha1.Sidecar - - // TaskWorkspace adds a workspace declaration. - // Deprecated: moved to internal/builder/v1alpha1 - TaskWorkspace = v1alpha1.TaskWorkspace - - // TaskStepTemplate adds a base container for all steps in the task. - // Deprecated: moved to internal/builder/v1alpha1 - TaskStepTemplate = v1alpha1.TaskStepTemplate - - // TaskVolume adds a volume with specified name to the TaskSpec. - // Any number of Volume modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskVolume = v1alpha1.TaskVolume - - // VolumeSource sets the VolumeSource to the Volume. - // Deprecated: moved to internal/builder/v1alpha1 - VolumeSource = v1alpha1.VolumeSource - - // TaskParam sets the Params to the TaskSpec - // Deprecated: moved to internal/builder/v1alpha1 - TaskParam = v1alpha1.TaskParam - - // TaskResources sets the Resources to the TaskSpec - // Deprecated: moved to internal/builder/v1alpha1 - TaskResources = v1alpha1.TaskResources - - // TaskResults sets the Results to the TaskSpec - // Deprecated: moved to internal/builder/v1alpha1 - TaskResults = v1alpha1.TaskResults - - // TaskResourcesInput adds a TaskResource as Inputs to the TaskResources - // Deprecated: moved to internal/builder/v1alpha1 - TaskResourcesInput = v1alpha1.TaskResourcesInput - - // TaskResourcesOutput adds a TaskResource as Outputs to the TaskResources - // Deprecated: moved to internal/builder/v1alpha1 - TaskResourcesOutput = v1alpha1.TaskResourcesOutput - - // TaskResultsOutput adds a TaskResult as Outputs to the TaskResources - // Deprecated: moved to internal/builder/v1alpha1 - TaskResultsOutput = v1alpha1.TaskResultsOutput - - // TaskInputs sets inputs to the TaskSpec. - // Any number of Inputs modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskInputs = v1alpha1.TaskInputs - - // TaskOutputs sets inputs to the TaskSpec. - // Any number of Outputs modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskOutputs = v1alpha1.TaskOutputs - - // InputsResource adds a resource, with specified name and type, to the Inputs. - // Any number of TaskResource modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - InputsResource = v1alpha1.InputsResource - - // ResourceOptional marks a TaskResource as optional. - // Deprecated: moved to internal/builder/v1alpha1 - ResourceOptional = v1alpha1.ResourceOptional - - // ResourceTargetPath sets the target path to a TaskResource. - // Deprecated: moved to internal/builder/v1alpha1 - ResourceTargetPath = v1alpha1.ResourceTargetPath - - // OutputsResource adds a resource, with specified name and type, to the Outputs. - // Deprecated: moved to internal/builder/v1alpha1 - OutputsResource = v1alpha1.OutputsResource - - // InputsParamSpec adds a ParamSpec, with specified name and type, to the Inputs. - // Any number of TaskParamSpec modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - InputsParamSpec = v1alpha1.InputsParamSpec - - // TaskRun creates a TaskRun with default values. - // Any number of TaskRun modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRun = v1alpha1.TaskRun - - // TaskRunNamespace sets the namespace for the TaskRun. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunNamespace = v1alpha1.TaskRunNamespace - - // TaskRunStatus sets the TaskRunStatus to tshe TaskRun - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunStatus = v1alpha1.TaskRunStatus - - // PodName sets the Pod name to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - PodName = v1alpha1.PodName - - // StatusCondition adds a StatusCondition to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - StatusCondition = v1alpha1.StatusCondition - - // TaskRunResult adds a result with the specified name and value to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunResult = v1alpha1.TaskRunResult - - // Retry adds a RetriesStatus (TaskRunStatus) to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - Retry = v1alpha1.Retry - - // StepState adds a StepState to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - StepState = v1alpha1.StepState - - // SidecarState adds a SidecarState to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - SidecarState = v1alpha1.SidecarState - - // TaskRunStartTime sets the start time to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunStartTime = v1alpha1.TaskRunStartTime - - // TaskRunCompletionTime sets the start time to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunCompletionTime = v1alpha1.TaskRunCompletionTime - - // TaskRunCloudEvent adds an event to the TaskRunStatus. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunCloudEvent = v1alpha1.TaskRunCloudEvent - - // TaskRunTimeout sets the timeout duration to the TaskRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunTimeout = v1alpha1.TaskRunTimeout - - // TaskRunNilTimeout sets the timeout duration to nil on the TaskRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunNilTimeout = v1alpha1.TaskRunNilTimeout - - // TaskRunNodeSelector sets the NodeSelector to the TaskRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunNodeSelector = v1alpha1.TaskRunNodeSelector - - // TaskRunTolerations sets the Tolerations to the TaskRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunTolerations = v1alpha1.TaskRunTolerations - - // TaskRunAffinity sets the Affinity to the TaskRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunAffinity = v1alpha1.TaskRunAffinity - - // TaskRunPodSecurityContext sets the SecurityContext to the TaskRunSpec (through PodTemplate). - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunPodSecurityContext = v1alpha1.TaskRunPodSecurityContext - - // StateTerminated sets Terminated to the StepState. - // Deprecated: moved to internal/builder/v1alpha1 - StateTerminated = v1alpha1.StateTerminated - - // SetStepStateTerminated sets Terminated state of a step. - // Deprecated: moved to internal/builder/v1alpha1 - SetStepStateTerminated = v1alpha1.SetStepStateTerminated - - // SetStepStateRunning sets Running state of a step. - // Deprecated: moved to internal/builder/v1alpha1 - SetStepStateRunning = v1alpha1.SetStepStateRunning - - // SetStepStateWaiting sets Waiting state of a step. - // Deprecated: moved to internal/builder/v1alpha1 - SetStepStateWaiting = v1alpha1.SetStepStateWaiting - - // TaskRunOwnerReference sets the OwnerReference, with specified kind and name, to the TaskRun. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunOwnerReference = v1alpha1.TaskRunOwnerReference - - // TaskRunLabels add the specified labels to the TaskRun. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunLabels = v1alpha1.TaskRunLabels - - // TaskRunLabel adds a label with the specified key and value to the TaskRun. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunLabel = v1alpha1.TaskRunLabel - - // TaskRunAnnotation adds an annotation with the specified key and value to the TaskRun. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunAnnotation = v1alpha1.TaskRunAnnotation - - // TaskRunSelfLink adds a SelfLink - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunSelfLink = v1alpha1.TaskRunSelfLink - - // TaskRunSpec sets the specified spec of the TaskRun. - // Any number of TaskRunSpec modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunSpec = v1alpha1.TaskRunSpec - - // TaskRunCancelled sets the status to cancel to the TaskRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunCancelled = v1alpha1.TaskRunCancelled - - // TaskRunTaskRef sets the specified Task reference to the TaskRunSpec. - // Any number of TaskRef modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunTaskRef = v1alpha1.TaskRunTaskRef - - // TaskRunSpecStatus sets the Status in the Spec, used for operations - // such as cancelling executing TaskRuns. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunSpecStatus = v1alpha1.TaskRunSpecStatus - - // TaskRefKind set the specified kind to the TaskRef. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRefKind = v1alpha1.TaskRefKind - - // TaskRefAPIVersion sets the specified api version to the TaskRef. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRefAPIVersion = v1alpha1.TaskRefAPIVersion - - // TaskRunTaskSpec sets the specified TaskRunSpec reference to the TaskRunSpec. - // Any number of TaskRunSpec modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunTaskSpec = v1alpha1.TaskRunTaskSpec - - // TaskRunServiceAccountName sets the serviceAccount to the TaskRunSpec. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunServiceAccountName = v1alpha1.TaskRunServiceAccountName - - // TaskRunParam sets the Params to the TaskSpec - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunParam = v1alpha1.TaskRunParam - - // TaskRunResources sets the TaskRunResources to the TaskRunSpec - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunResources = v1alpha1.TaskRunResources - - // TaskRunResourcesInput adds a TaskRunResource as Inputs to the TaskRunResources - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunResourcesInput = v1alpha1.TaskRunResourcesInput - - // TaskRunResourcesOutput adds a TaskRunResource as Outputs to the TaskRunResources - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunResourcesOutput = v1alpha1.TaskRunResourcesOutput - - // TaskRunInputs sets inputs to the TaskRunSpec. - // Any number of TaskRunInputs modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunInputs = v1alpha1.TaskRunInputs - - // TaskRunInputsParam add a param, with specified name and value, to the TaskRunInputs. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunInputsParam = v1alpha1.TaskRunInputsParam - - // TaskRunInputsResource adds a resource, with specified name, to the TaskRunInputs. - // Any number of TaskResourceBinding modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunInputsResource = v1alpha1.TaskRunInputsResource - - // TaskResourceBindingRef set the PipelineResourceRef name to the TaskResourceBinding. - // Deprecated: moved to internal/builder/v1alpha1 - TaskResourceBindingRef = v1alpha1.TaskResourceBindingRef - - // TaskResourceBindingResourceSpec set the PipelineResourceResourceSpec to the TaskResourceBinding. - // Deprecated: moved to internal/builder/v1alpha1 - TaskResourceBindingResourceSpec = v1alpha1.TaskResourceBindingResourceSpec - - // TaskResourceBindingRefAPIVersion set the PipelineResourceRef APIVersion to the TaskResourceBinding. - // Deprecated: moved to internal/builder/v1alpha1 - TaskResourceBindingRefAPIVersion = v1alpha1.TaskResourceBindingRefAPIVersion - - // TaskResourceBindingPaths add any number of path to the TaskResourceBinding. - // Deprecated: moved to internal/builder/v1alpha1 - TaskResourceBindingPaths = v1alpha1.TaskResourceBindingPaths - - // TaskRunOutputs sets inputs to the TaskRunSpec. - // Any number of TaskRunOutputs modifier can be passed to transform it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunOutputs = v1alpha1.TaskRunOutputs - - // TaskRunOutputsResource adds a TaskResourceBinding, with specified name, to the TaskRunOutputs. - // Any number of TaskResourceBinding modifier can be passed to modifiy it. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunOutputsResource = v1alpha1.TaskRunOutputsResource - - // TaskRunWorkspaceEmptyDir adds a workspace binding to an empty dir volume source. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunWorkspaceEmptyDir = v1alpha1.TaskRunWorkspaceEmptyDir - - // TaskRunWorkspacePVC adds a workspace binding to a PVC volume source. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunWorkspacePVC = v1alpha1.TaskRunWorkspacePVC - - // TaskRunWorkspaceVolumeClaimTemplate adds a workspace binding with a VolumeClaimTemplate volume source. - // Deprecated: moved to internal/builder/v1alpha1 - TaskRunWorkspaceVolumeClaimTemplate = v1alpha1.TaskRunWorkspaceVolumeClaimTemplate -) diff --git a/test/builder/task_test.go b/test/builder/task_test.go deleted file mode 100644 index cb612e22b13..00000000000 --- a/test/builder/task_test.go +++ /dev/null @@ -1,422 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder_test - -import ( - "testing" - "time" - - "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/config" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - 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" -) - -var ( - gitResource = tb.PipelineResource("git-resource", tb.PipelineResourceNamespace("foo"), tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "https://foo.git"), - )) - anotherGitResource = tb.PipelineResource("another-git-resource", tb.PipelineResourceNamespace("foo"), tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, tb.PipelineResourceSpecParam("URL", "https://foobar.git"), - )) -) - -func TestTask(t *testing.T) { - task := tb.Task("test-task", tb.TaskType(), tb.TaskSpec( - tb.TaskInputs( - tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit, tb.ResourceTargetPath("/foo/bar")), - tb.InputsResource("optional_workspace", v1alpha1.PipelineResourceTypeGit, tb.ResourceOptional(true)), - tb.InputsParamSpec("param", v1alpha1.ParamTypeString, tb.ParamSpecDescription("mydesc"), tb.ParamSpecDefault("default")), - tb.InputsParamSpec("array-param", v1alpha1.ParamTypeString, tb.ParamSpecDescription("desc"), tb.ParamSpecDefault("array", "values")), - ), - tb.TaskOutputs( - tb.OutputsResource("myotherimage", v1alpha1.PipelineResourceTypeImage), - tb.OutputsResource("myoptionalimage", v1alpha1.PipelineResourceTypeImage, tb.ResourceOptional(true)), - ), - tb.TaskDescription("Test Task"), - tb.Step("myimage", tb.StepName("mycontainer"), tb.StepCommand("/mycmd"), tb.StepArgs( - "--my-other-arg=$(inputs.resources.workspace.url)", - )), - tb.Step("myimage2", tb.StepScript("echo foo")), - tb.TaskVolume("foo", tb.VolumeSource(corev1.VolumeSource{ - HostPath: &corev1.HostPathVolumeSource{Path: "/foo/bar"}, - })), - tb.TaskStepTemplate( - tb.EnvVar("FRUIT", "BANANA"), - ), - tb.TaskWorkspace("bread", "kind of bread", "/bread/path", false), - ), tb.TaskNamespace("foo")) - expectedTask := &v1alpha1.Task{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "tekton.dev/v1alpha1", - Kind: "Task", - }, - ObjectMeta: metav1.ObjectMeta{Name: "test-task", Namespace: "foo"}, - Spec: v1alpha1.TaskSpec{ - TaskSpec: v1beta1.TaskSpec{ - Description: "Test Task", - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "mycontainer", - Image: "myimage", - Command: []string{"/mycmd"}, - Args: []string{"--my-other-arg=$(inputs.resources.workspace.url)"}, - }}, {Script: "echo foo", Container: corev1.Container{ - Image: "myimage2", - }}}, - Volumes: []corev1.Volume{{ - Name: "foo", - VolumeSource: corev1.VolumeSource{ - HostPath: &corev1.HostPathVolumeSource{Path: "/foo/bar"}, - }, - }}, - StepTemplate: &corev1.Container{ - Env: []corev1.EnvVar{{ - Name: "FRUIT", - Value: "BANANA", - }}, - }, - Workspaces: []v1alpha1.WorkspaceDeclaration{{ - Name: "bread", - Description: "kind of bread", - MountPath: "/bread/path", - ReadOnly: false, - }}, - }, - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "workspace", - Type: v1alpha1.PipelineResourceTypeGit, - TargetPath: "/foo/bar", - }}, { - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "optional_workspace", - Type: v1alpha1.PipelineResourceTypeGit, - TargetPath: "", - Optional: true, - }}}, - Params: []v1alpha1.ParamSpec{{ - Name: "param", - Type: v1alpha1.ParamTypeString, - Description: "mydesc", - Default: tb.ArrayOrString("default"), - }, { - Name: "array-param", - Type: v1alpha1.ParamTypeString, - Description: "desc", - Default: tb.ArrayOrString("array", "values"), - }}}, - Outputs: &v1alpha1.Outputs{ - Resources: []v1alpha1.TaskResource{{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "myotherimage", - Type: v1alpha1.PipelineResourceTypeImage, - }}, { - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "myoptionalimage", - Type: v1alpha1.PipelineResourceTypeImage, - TargetPath: "", - Optional: true, - }}}, - }, - }, - } - if d := cmp.Diff(expectedTask, task); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func TestClusterTask(t *testing.T) { - task := tb.ClusterTask("test-clustertask", tb.ClusterTaskType(), tb.ClusterTaskSpec( - tb.Step("myimage", tb.StepCommand("/mycmd"), tb.StepArgs( - "--my-other-arg=$(inputs.resources.workspace.url)", - )), - )) - expectedTask := &v1alpha1.ClusterTask{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "tekton.dev/v1alpha1", - Kind: "ClusterTask", - }, - ObjectMeta: metav1.ObjectMeta{Name: "test-clustertask"}, - Spec: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Image: "myimage", - Command: []string{"/mycmd"}, - Args: []string{"--my-other-arg=$(inputs.resources.workspace.url)"}, - }}}, - }}, - } - if d := cmp.Diff(expectedTask, task); d != "" { - t.Fatalf("Task diff -want, +got: %v", d) - } -} - -func TestTaskRunWithTaskRef(t *testing.T) { - var trueB = true - terminatedState := corev1.ContainerStateTerminated{Reason: "Completed"} - - taskRun := tb.TaskRun("test-taskrun", - tb.TaskRunNamespace("foo"), - tb.TaskRunOwnerReference("PipelineRun", "test", - tb.OwnerReferenceAPIVersion("a1"), - tb.Controller, tb.BlockOwnerDeletion, - ), - tb.TaskRunLabels(map[string]string{"label-2": "label-value-2", "label-3": "label-value-3"}), - tb.TaskRunLabel("label", "label-value"), - tb.TaskRunSpec( - tb.TaskRunTaskRef("task-output", - tb.TaskRefKind(v1alpha1.ClusterTaskKind), - tb.TaskRefAPIVersion("a1"), - ), - tb.TaskRunInputs( - tb.TaskRunInputsResource(gitResource.Name, - tb.TaskResourceBindingRef("my-git"), - tb.TaskResourceBindingPaths("source-folder"), - tb.TaskResourceBindingRefAPIVersion("a1"), - ), - tb.TaskRunInputsResource(anotherGitResource.Name, - tb.TaskResourceBindingPaths("source-folder"), - tb.TaskResourceBindingResourceSpec(&v1alpha1.PipelineResourceSpec{Type: v1alpha1.PipelineResourceTypeCluster}), - ), - tb.TaskRunInputsParam("iparam", "ivalue"), - tb.TaskRunInputsParam("arrayparam", "array", "values"), - ), - tb.TaskRunOutputs( - tb.TaskRunOutputsResource(gitResource.Name, - tb.TaskResourceBindingRef(gitResource.Name), - tb.TaskResourceBindingPaths("output-folder"), - ), - ), - tb.TaskRunWorkspaceEmptyDir("bread", "path"), - tb.TaskRunWorkspacePVC("pizza", "", "pool-party"), - ), - tb.TaskRunStatus( - tb.PodName("my-pod-name"), - tb.StatusCondition(apis.Condition{Type: apis.ConditionSucceeded}), - tb.StepState(tb.StateTerminated(127)), - tb.SidecarState( - tb.SidecarStateName("sidecar"), - tb.SidecarStateImageID("ImageID"), - tb.SidecarStateContainerName("ContainerName"), - tb.SetSidecarStateTerminated(terminatedState), - ), - ), - ) - expectedTaskRun := &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun", Namespace: "foo", - OwnerReferences: []metav1.OwnerReference{{ - Name: "test", - Kind: "PipelineRun", - APIVersion: "a1", - Controller: &trueB, - BlockOwnerDeletion: &trueB, - }}, - Labels: map[string]string{ - "label": "label-value", - "label-2": "label-value-2", - "label-3": "label-value-3", - }, - Annotations: map[string]string{}, - }, - Spec: v1alpha1.TaskRunSpec{ - Inputs: &v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskResourceBinding{{ - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: "git-resource", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "my-git", - APIVersion: "a1", - }, - }, - Paths: []string{"source-folder"}, - }, { - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: "another-git-resource", - ResourceSpec: &v1alpha1.PipelineResourceSpec{Type: v1alpha1.PipelineResourceType("cluster")}, - }, - Paths: []string{"source-folder"}, - }}, - Params: []v1alpha1.Param{{ - Name: "iparam", - Value: *tb.ArrayOrString("ivalue"), - }, { - Name: "arrayparam", - Value: *tb.ArrayOrString("array", "values"), - }}, - }, - Outputs: &v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskResourceBinding{{ - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: "git-resource", - ResourceRef: &v1alpha1.PipelineResourceRef{ - Name: "git-resource", - }, - }, - Paths: []string{"output-folder"}, - }}, - }, - Resources: &v1beta1.TaskRunResources{}, - Timeout: &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}, - TaskRef: &v1alpha1.TaskRef{ - Name: "task-output", - Kind: v1alpha1.ClusterTaskKind, - APIVersion: "a1", - }, - Workspaces: []v1alpha1.WorkspaceBinding{{ - Name: "bread", - SubPath: "path", - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }, { - Name: "pizza", - SubPath: "", - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: "pool-party", - }, - }}, - }, - Status: v1alpha1.TaskRunStatus{ - Status: duckv1beta1.Status{ - Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}}, - }, - TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ - PodName: "my-pod-name", - Sidecars: []v1beta1.SidecarState{{ - Name: "sidecar", - ImageID: "ImageID", - ContainerName: "ContainerName", - ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - Reason: "Completed", - }, - }, - }}, - Steps: []v1alpha1.StepState{{ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ExitCode: 127}, - }}}, - }, - }, - } - if d := cmp.Diff(expectedTaskRun, taskRun); d != "" { - t.Fatalf("TaskRun diff -want, +got: %v", d) - } -} - -func TestTaskRunWithTaskSpec(t *testing.T) { - taskRun := tb.TaskRun("test-taskrun", - tb.TaskRunNamespace("foo"), - tb.TaskRunSpec( - tb.TaskRunTaskSpec( - tb.Step("image", tb.StepCommand("/mycmd")), - tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit, tb.ResourceOptional(true))), - ), - tb.TaskRunServiceAccountName("sa"), - tb.TaskRunTimeout(2*time.Minute), - tb.TaskRunSpecStatus(v1alpha1.TaskRunSpecStatusCancelled), - )) - expectedTaskRun := &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun", Namespace: "foo", - Annotations: map[string]string{}, - }, - Spec: v1alpha1.TaskRunSpec{ - TaskSpec: &v1alpha1.TaskSpec{ - TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Image: "image", - Command: []string{"/mycmd"}, - }}}, - }, - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "workspace", - Type: v1alpha1.PipelineResourceTypeGit, - Optional: true, - }}}, - Params: nil, - }, - }, - Resources: &v1beta1.TaskRunResources{}, - ServiceAccountName: "sa", - Status: v1alpha1.TaskRunSpecStatusCancelled, - Timeout: &metav1.Duration{Duration: 2 * time.Minute}, - }, - } - if d := cmp.Diff(expectedTaskRun, taskRun); d != "" { - t.Fatalf("TaskRun diff -want, +got: %v", d) - } -} - -func TestTaskRunWithPodTemplate(t *testing.T) { - taskRun := tb.TaskRun("test-taskrun", - tb.TaskRunNamespace("foo"), - tb.TaskRunSpec( - tb.TaskRunTaskSpec( - tb.Step("image", tb.StepCommand("/mycmd")), - tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit, tb.ResourceOptional(true))), - ), - tb.TaskRunServiceAccountName("sa"), - tb.TaskRunTimeout(2*time.Minute), - tb.TaskRunSpecStatus(v1alpha1.TaskRunSpecStatusCancelled), - tb.TaskRunNodeSelector(map[string]string{ - "label": "value", - }), - )) - expectedTaskRun := &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun", Namespace: "foo", - Annotations: map[string]string{}, - }, - Spec: v1alpha1.TaskRunSpec{ - TaskSpec: &v1alpha1.TaskSpec{ - TaskSpec: v1beta1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Image: "image", - Command: []string{"/mycmd"}, - }}}, - }, - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: "workspace", - Type: v1alpha1.PipelineResourceTypeGit, - Optional: true, - }}}, - Params: nil, - }, - }, - PodTemplate: &v1alpha1.PodTemplate{ - NodeSelector: map[string]string{ - "label": "value", - }, - }, - Resources: &v1beta1.TaskRunResources{}, - ServiceAccountName: "sa", - Status: v1alpha1.TaskRunSpecStatusCancelled, - Timeout: &metav1.Duration{Duration: 2 * time.Minute}, - }, - } - if d := cmp.Diff(expectedTaskRun, taskRun); d != "" { - t.Fatalf("TaskRun diff -want, +got: %v", d) - } -} diff --git a/test/v1alpha1/sidecar_test.go b/test/v1alpha1/sidecar_test.go index 3fe5a9e7c07..4964f65469f 100644 --- a/test/v1alpha1/sidecar_test.go +++ b/test/v1alpha1/sidecar_test.go @@ -23,7 +23,8 @@ import ( "testing" "time" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" knativetest "knative.dev/pkg/test" @@ -64,26 +65,31 @@ func TestSidecarTaskSupport(t *testing.T) { t.Run(test.desc, func(t *testing.T) { sidecarTaskName := fmt.Sprintf("%s-%d", sidecarTaskName, i) sidecarTaskRunName := fmt.Sprintf("%s-%d", sidecarTaskRunName, i) - task := tb.Task(sidecarTaskName, - tb.TaskSpec( - tb.Step( - "busybox", - tb.StepName(primaryContainerName), - tb.StepCommand(test.stepCommand...), - ), - tb.Sidecar( - sidecarContainerName, - "busybox", - tb.Command(test.sidecarCommand...), - ), - ), - ) - - taskRun := tb.TaskRun(sidecarTaskRunName, - tb.TaskRunSpec(tb.TaskRunTaskRef(sidecarTaskName), - tb.TaskRunTimeout(1*time.Minute), - ), - ) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{Name: sidecarTaskName}, + Spec: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{ + Steps: []v1beta1.Step{{Container: corev1.Container{ + Image: "busybox", + Name: primaryContainerName, + Command: test.stepCommand, + }}}, + Sidecars: []v1beta1.Sidecar{{Container: corev1.Container{ + Image: "busybox", + Name: sidecarContainerName, + Command: test.sidecarCommand, + }}}, + }}, + } + + taskRun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{Name: sidecarTaskRunName}, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: sidecarTaskName, + }, + Timeout: &metav1.Duration{time.Minute}, + }, + } t.Logf("Creating Task %q", sidecarTaskName) if _, err := clients.TaskClient.Create(task); err != nil { diff --git a/test/v1alpha1/wait_test.go b/test/v1alpha1/wait_test.go index 83b1c7e0cfc..dfdabb351f5 100644 --- a/test/v1alpha1/wait_test.go +++ b/test/v1alpha1/wait_test.go @@ -21,17 +21,14 @@ import ( "testing" "time" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/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" rtesting "knative.dev/pkg/reconciler/testing" ) -const ( - waitNamespace = "wait" -) - var ( success = apis.Condition{Type: apis.ConditionSucceeded, Status: corev1.ConditionTrue} failure = apis.Condition{Type: apis.ConditionSucceeded, Status: corev1.ConditionFalse} @@ -39,30 +36,27 @@ var ( func TestWaitForTaskRunStateSucceed(t *testing.T) { d := Data{ - TaskRuns: []*v1alpha1.TaskRun{ - tb.TaskRun("foo", - tb.TaskRunNamespace(waitNamespace), - tb.TaskRunStatus( - tb.StatusCondition(success), - )), - }, + TaskRuns: []*v1alpha1.TaskRun{{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Status: v1alpha1.TaskRunStatus{Status: duckv1beta1.Status{ + Conditions: []apis.Condition{success}, + }}, + }}, } c, cancel := fakeClients(t, d) defer cancel() - err := WaitForTaskRunState(c, "foo", Succeed("foo"), "TestTaskRunSucceed") - if err != nil { + if err := WaitForTaskRunState(c, "foo", Succeed("foo"), "TestTaskRunSucceed"); err != nil { t.Fatal(err) } } func TestWaitForTaskRunStateFailed(t *testing.T) { d := Data{ - TaskRuns: []*v1alpha1.TaskRun{ - tb.TaskRun("foo", - tb.TaskRunNamespace(waitNamespace), - tb.TaskRunStatus( - tb.StatusCondition(failure), - )), - }, + TaskRuns: []*v1alpha1.TaskRun{{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Status: v1alpha1.TaskRunStatus{Status: duckv1beta1.Status{ + Conditions: []apis.Condition{failure}, + }}, + }}, } c, cancel := fakeClients(t, d) defer cancel() @@ -74,11 +68,12 @@ func TestWaitForTaskRunStateFailed(t *testing.T) { func TestWaitForPipelineRunStateSucceed(t *testing.T) { d := Data{ - PipelineRuns: []*v1alpha1.PipelineRun{ - tb.PipelineRun("bar", tb.PipelineRunNamespace(waitNamespace), tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(success), - )), - }, + PipelineRuns: []*v1alpha1.PipelineRun{{ + ObjectMeta: metav1.ObjectMeta{Name: "bar"}, + Status: v1alpha1.PipelineRunStatus{Status: duckv1beta1.Status{ + Conditions: []apis.Condition{success}, + }}, + }}, } c, cancel := fakeClients(t, d) defer cancel() @@ -90,11 +85,12 @@ func TestWaitForPipelineRunStateSucceed(t *testing.T) { func TestWaitForPipelineRunStateFailed(t *testing.T) { d := Data{ - PipelineRuns: []*v1alpha1.PipelineRun{ - tb.PipelineRun("bar", tb.PipelineRunNamespace(waitNamespace), tb.PipelineRunStatus( - tb.PipelineRunStatusCondition(failure), - )), - }, + PipelineRuns: []*v1alpha1.PipelineRun{{ + ObjectMeta: metav1.ObjectMeta{Name: "bar"}, + Status: v1alpha1.PipelineRunStatus{Status: duckv1beta1.Status{ + Conditions: []apis.Condition{failure}, + }}, + }}, } c, cancel := fakeClients(t, d) defer cancel() @@ -108,12 +104,11 @@ func fakeClients(t *testing.T, d Data) (*clients, func()) { ctx, _ := rtesting.SetupFakeContext(t) ctx, cancel := context.WithCancel(ctx) fakeClients, _ := SeedTestData(t, ctx, d) - // c.KubeClient = fakeClients.Kube return &clients{ - PipelineClient: fakeClients.Pipeline.TektonV1alpha1().Pipelines(waitNamespace), - PipelineResourceClient: fakeClients.Resource.TektonV1alpha1().PipelineResources(waitNamespace), - PipelineRunClient: fakeClients.Pipeline.TektonV1alpha1().PipelineRuns(waitNamespace), - TaskClient: fakeClients.Pipeline.TektonV1alpha1().Tasks(waitNamespace), - TaskRunClient: fakeClients.Pipeline.TektonV1alpha1().TaskRuns(waitNamespace), + PipelineClient: fakeClients.Pipeline.TektonV1alpha1().Pipelines(""), + PipelineResourceClient: fakeClients.Resource.TektonV1alpha1().PipelineResources(""), + PipelineRunClient: fakeClients.Pipeline.TektonV1alpha1().PipelineRuns(""), + TaskClient: fakeClients.Pipeline.TektonV1alpha1().Tasks(""), + TaskRunClient: fakeClients.Pipeline.TektonV1alpha1().TaskRuns(""), }, cancel }