diff --git a/pkg/cmd/pipeline/start.go b/pkg/cmd/pipeline/start.go index 1e3c2f214..ada6dddab 100644 --- a/pkg/cmd/pipeline/start.go +++ b/pkg/cmd/pipeline/start.go @@ -66,6 +66,7 @@ type resourceOptionsFilter struct { cluster []string storage []string pullRequest []string + cloudEvent []string } // NameArg validates that the first argument is a valid pipeline name @@ -237,10 +238,9 @@ func (opt *startOptions) getInputResources(resources resourceOptionsFilter, pipe return err } opt.Resources = append(opt.Resources, res.Name+"="+newres.Name) - } else { - name := strings.TrimSpace(strings.Split(ans, " ")[0]) - opt.Resources = append(opt.Resources, res.Name+"="+name) } + name := strings.TrimSpace(strings.Split(ans, " ")[0]) + opt.Resources = append(opt.Resources, res.Name+"="+name) } return nil } @@ -329,6 +329,13 @@ func getPipelineResourcesByFormat(resources []v1alpha1.PipelineResource) (ret re } } ret.cluster = append(ret.cluster, fmt.Sprintf("%s (%s)", res.Name, output)) + case "cloudEvent": + for _, param := range res.Spec.Params { + if param.Name == "targetURI" { + output = param.Value + output + } + } + ret.cloudEvent = append(ret.cloudEvent, fmt.Sprintf("%s (%s)", res.Name, output)) } } return @@ -350,6 +357,9 @@ func getOptionsByType(resources resourceOptionsFilter, restype string) []string if restype == "storage" { return resources.storage } + if restype == "cloudEvent" { + return resources.cloudEvent + } return []string{} } @@ -566,6 +576,7 @@ func (opt *startOptions) createPipelineResource(resName string, resType v1alpha1 v1alpha1.PipelineResourceTypeImage: res.AskImageParams, v1alpha1.PipelineResourceTypeCluster: res.AskClusterParams, v1alpha1.PipelineResourceTypePullRequest: res.AskPullRequestParams, + v1alpha1.PipelineResourceTypeCloudEvent: res.AskCloudEventParams, } if res.PipelineResource.Spec.Type != "" { if err := resourceTypeParams[res.PipelineResource.Spec.Type](); err != nil { diff --git a/pkg/cmd/pipeline/start_test.go b/pkg/cmd/pipeline/start_test.go index c74a6a593..115ebc3e3 100644 --- a/pkg/cmd/pipeline/start_test.go +++ b/pkg/cmd/pipeline/start_test.go @@ -1007,6 +1007,11 @@ func Test_getPipelineResourceByFormat(t *testing.T) { tb.PipelineResourceSpecParam("location", "/home/tektoncd"), ), ), + tb.PipelineResource("scaffold-cloud", "ns", + tb.PipelineResourceSpec("cloudEvent", + tb.PipelineResourceSpecParam("targetURI", "http://sink:8080"), + ), + ), } ns := []*corev1.Namespace{ @@ -1051,6 +1056,12 @@ func Test_getPipelineResourceByFormat(t *testing.T) { t.Errorf("output storage = %v, want %v", output, expected) } + output = getOptionsByType(resFormat, "cloudEvent") + expected = []string{"scaffold-cloud (http://sink:8080)"} + if !reflect.DeepEqual(output, expected) { + t.Errorf("output storage = %v, want %v", output, expected) + } + output = getOptionsByType(resFormat, "file") expected = []string{} if !reflect.DeepEqual(output, expected) { @@ -2227,6 +2238,101 @@ func Test_start_pipeline_clusterRes_withExistingRes_createNew(t *testing.T) { } } +func Test_start_pipeline_cloudEventRes_withExistingRes_createNew(t *testing.T) { + + pipelineName := "cloudpipeline" + + cs, _ := test.SeedTestData(t, pipelinetest.Data{ + Pipelines: []*v1alpha1.Pipeline{ + tb.Pipeline(pipelineName, "ns", + tb.PipelineSpec( + tb.PipelineDeclaredResource("cloudres", "cloudEvent"), + tb.PipelineTask("unit-test-1", "unit-test-task", + tb.PipelineTaskInputResource("clusres", "clusterresource"), + ), + ), + ), + }, + + PipelineResources: []*v1alpha1.PipelineResource{ + tb.PipelineResource("cloudresource", "ns", + tb.PipelineResourceSpec("cloudEvent", + tb.PipelineResourceSpecParam("targetURI", "https://10.20.30.40/"), + ), + ), + }, + }) + + tests := []promptTest{ + { + name: "newCloudResource", + cmdArgs: []string{pipelineName}, + + procedure: func(c *expect.Console) error { + if _, err := c.ExpectString("Choose the cloudEvent resource to use for cloudres"); err != nil { + return err + } + + if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { + return err + } + + if _, err := c.ExpectString("create new \"cloudEvent\" resource"); err != nil { + return err + } + + if _, err := c.Send(string(terminal.KeyEnter)); err != nil { + return err + } + + if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { + return err + } + + if _, err := c.SendLine("newcloudresource"); err != nil { + return err + } + + if _, err := c.ExpectString("Enter a value for targetURI :"); err != nil { + return err + } + + if _, err := c.SendLine("https://10.10.10.10"); err != nil { + return err + } + + if _, err := c.Send(string(terminal.KeyEnter)); err != nil { + return err + } + + if _, err := c.ExpectEOF(); err != nil { + return err + } + + tekton := cs.Pipeline.Tekton() + runs, err := tekton.PipelineRuns("ns").List(v1.ListOptions{}) + if err != nil { + return err + } + + if runs.Items != nil && runs.Items[0].Spec.PipelineRef.Name != pipelineName { + return errors.New("pipelinerun not found") + } + + c.Close() + return nil + }, + }, + } + opts := startOpts("ns", cs, false, "svc1", []string{"task1=svc1"}) + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + opts.RunPromptTest(t, test) + }) + } +} + func startOpts(ns string, cs pipelinetest.Clients, last bool, svc string, svcs []string) *startOptions { p := test.Params{ Kube: cs.Kube, diff --git a/pkg/cmd/pipelineresource/list.go b/pkg/cmd/pipelineresource/list.go index 1fc8c10a2..eed3891c5 100644 --- a/pkg/cmd/pipelineresource/list.go +++ b/pkg/cmd/pipelineresource/list.go @@ -166,7 +166,8 @@ func details(pre v1alpha1.PipelineResource) string { var key = "url" if pre.Spec.Type == v1alpha1.PipelineResourceTypeStorage { key = "location" - } else if pre.Spec.Type == v1alpha1.PipelineResourceTypeCloudEvent { + } + if pre.Spec.Type == v1alpha1.PipelineResourceTypeCloudEvent { key = "targeturi" }