From d8ddbdef4fe5de2c614772bba444d5e509e27f1c Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Thu, 19 Mar 2020 07:06:27 +0530 Subject: [PATCH] Add TaskResults to testbuilder Signed-off-by: Vibhav Bobade --- test/builder/task.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/builder/task.go b/test/builder/task.go index 36a1271726c..cc3c4633110 100644 --- a/test/builder/task.go +++ b/test/builder/task.go @@ -67,6 +67,9 @@ type TaskRunStatusOp func(*v1alpha1.TaskRunStatus) // TaskRefOp is an operation which modify a TaskRef struct. type TaskRefOp func(*v1alpha1.TaskRef) +// TaskResultOp is an operation which modifies there +type TaskResultOp func(result *v1beta1.TaskResult) + // TaskRunInputsOp is an operation which modify a TaskRunInputs struct. type TaskRunInputsOp func(*v1alpha1.TaskRunInputs) @@ -247,6 +250,17 @@ func TaskResources(ops ...TaskResourcesOp) TaskSpecOp { } } +// TaskResults sets the Results to the TaskSpec +func TaskResults(name, desc string) TaskSpecOp { + return func(spec *v1alpha1.TaskSpec) { + r := &v1beta1.TaskResult{ + Name: name, + Description: desc, + } + spec.Results = append(spec.Results, *r) + } +} + // TaskResourcesInput adds a TaskResource as Inputs to the TaskResources func TaskResourcesInput(name string, resourceType v1alpha1.PipelineResourceType, ops ...TaskResourceOp) TaskResourcesOp { return func(r *v1beta1.TaskResources) { @@ -279,6 +293,19 @@ func TaskResourcesOutput(name string, resourceType v1alpha1.PipelineResourceType } } +// TaskResultsOutput adds a TaskResult as Outputs to the TaskResources +func TaskResultsOutput(name, desc string, ops ...TaskResultOp) TaskResultOp { + return func(result *v1beta1.TaskResult) { + r := &v1beta1.TaskResult{ + Name: name, + Description: desc, + } + for _, op := range ops { + op(r) + } + } +} + // TaskInputs sets inputs to the TaskSpec. // Any number of Inputs modifier can be passed to transform it. func TaskInputs(ops ...InputsOp) TaskSpecOp {