From f84198bd1cb612a0fa22a2a1246c46d5a91df4ed Mon Sep 17 00:00:00 2001 From: Christie Wilson Date: Thu, 3 Jan 2019 11:49:49 -0800 Subject: [PATCH] =?UTF-8?q?Use=20test=20builders=20and=20fix=20`providedBy?= =?UTF-8?q?`=20example=20=F0=9F=91=B7=E2=99=80=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In https://github.com/knative/build-pipeline/pull/342 I added docs and validation for the `providedBy` field, but I missed some feedback from @vdemeester before the PR was merged, so I'm addressing it now! The change to use the builders, even just for `PipelineResources`, removes a surprising amount of boilerplate! It doesn't seem like I can really use the builders for constructing the `state` object (slice of `ResolvedPipelineRunTask`) unless we add builder for `ResolvedPipelineRunTask`. That might be a good idea, however I'm planning to iterate on some of this for #320 and #168 (maybe) so I'm inclined to wait - open to other ideas tho! --- docs/using.md | 1 + .../resources/pipelinerunresolution_test.go | 28 +++---------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/docs/using.md b/docs/using.md index 5bc3c5a0d43..6be86bdfbd7 100644 --- a/docs/using.md +++ b/docs/using.md @@ -77,6 +77,7 @@ This is the corresponding `PipelineRun` spec: name: skaffold-image-leeroy-app - name: deploy-app ... + inputs: - name: image resourceRef: name: skaffold-image-leeroy-app diff --git a/pkg/reconciler/v1alpha1/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/v1alpha1/pipelinerun/resources/pipelinerunresolution_test.go index b6aa32a025f..7c73cf6add4 100644 --- a/pkg/reconciler/v1alpha1/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/v1alpha1/pipelinerun/resources/pipelinerunresolution_test.go @@ -28,6 +28,7 @@ import ( "github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1" "github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/taskrun/resources" + tb "github.com/knative/build-pipeline/test/builder" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -563,14 +564,7 @@ func TestGetPipelineConditionStatus(t *testing.T) { } func TestValidateProvidedBy(t *testing.T) { - r := &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "holygrail", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - }, - } + r := tb.PipelineResource("holygrail", namespace, tb.PipelineResourceSpec(v1alpha1.PipelineResourceTypeImage)) state := []*ResolvedPipelineRunTask{{ PipelineTask: &v1alpha1.PipelineTask{ Name: "quest", @@ -616,22 +610,8 @@ func TestValidateProvidedBy(t *testing.T) { } func TestValidateProvidedBy_Invalid(t *testing.T) { - r := &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "holygrail", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - }, - } - otherR := &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "holyhandgrenade", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - }, - } + r := tb.PipelineResource("holygrail", namespace, tb.PipelineResourceSpec(v1alpha1.PipelineResourceTypeImage)) + otherR := tb.PipelineResource("holyhandgrenade", namespace, tb.PipelineResourceSpec(v1alpha1.PipelineResourceTypeImage)) for _, tc := range []struct { name string