From 50dcd0bbee031b9e0d8c242dc55ac2707d35d922 Mon Sep 17 00:00:00 2001 From: Christie Wilson Date: Thu, 22 Nov 2018 13:01:45 -0800 Subject: [PATCH] Use resolved TaskRun to validate TaskRun With this change, we can use the resolved TaskRun when validating the TaskRun, so we no longer need access to the reconciler or to do any listing when validating the TaskRun. This is a step along the way to #213. Next we can do a similar refactoring to the PipelineRun validation. (The goal is that we can share the validation logic, since it's looking at the same thing just the structure of the input objects is different.) We'll probably also separate the param validation out from the resource validation. The current validation will miss the case where extra resources or parameters that aren't needed are supplied (this was the case already). --- .../v1alpha1/pipelinerun/validate.go | 1 + pkg/reconciler/v1alpha1/taskrun/taskrun.go | 19 +- .../v1alpha1/taskrun/taskrun_test.go | 2 +- pkg/reconciler/v1alpha1/taskrun/validate.go | 87 +--- .../v1alpha1/taskrun/validate_test.go | 457 ++++++------------ 5 files changed, 191 insertions(+), 375 deletions(-) diff --git a/pkg/reconciler/v1alpha1/pipelinerun/validate.go b/pkg/reconciler/v1alpha1/pipelinerun/validate.go index 33b5035cf39..808d5bd93b0 100644 --- a/pkg/reconciler/v1alpha1/pipelinerun/validate.go +++ b/pkg/reconciler/v1alpha1/pipelinerun/validate.go @@ -91,6 +91,7 @@ func validatePipelineTaskAndTask(c *Reconciler, ptask v1alpha1.PipelineTask, tas } } for _, inputResourceParam := range task.Spec.Inputs.Params { + // TODO(#213): should check if the param has default values here if _, ok := paramsMapping[inputResourceParam.Name]; !ok { return fmt.Errorf("input param %q not provided for pipeline task %q (task %q)", inputResourceParam.Name, ptask.Name, task.Name) } diff --git a/pkg/reconciler/v1alpha1/taskrun/taskrun.go b/pkg/reconciler/v1alpha1/taskrun/taskrun.go index 0626eb5b31b..1deb9a7db3f 100644 --- a/pkg/reconciler/v1alpha1/taskrun/taskrun.go +++ b/pkg/reconciler/v1alpha1/taskrun/taskrun.go @@ -51,8 +51,12 @@ const ( // Task couldn't be found ReasonCouldntGetTask = "CouldntGetTask" + // ReasonFailedResolution indicated that the reason for failure status is + // that references within the TaskRun could not be resolved + ReasonFailedResolution = "TaskRunResolutionFailed" + // ReasonFailedValidation indicated that the reason for failure status is - // that pipelinerun failed runtime validation + // that taskrun failed runtime validation ReasonFailedValidation = "TaskRunValidationFailed" // ReasonRunning indicates that the reason for the inprogress status is that the TaskRun @@ -177,7 +181,18 @@ func (c *Reconciler) Reconcile(ctx context.Context, key string) error { } func (c *Reconciler) reconcile(ctx context.Context, tr *v1alpha1.TaskRun) error { - if err := validateTaskRun(c, tr); err != nil { + rtr, err := resources.ResolveTaskRun(&tr.Spec, c.taskLister.Tasks(tr.Namespace).Get, c.resourceLister.PipelineResources(tr.Namespace).Get) + if err != nil { + c.Logger.Error("Failed to resolve references for taskrun %s with error %v", tr.Name, err) + tr.Status.SetCondition(&duckv1alpha1.Condition{ + Type: duckv1alpha1.ConditionSucceeded, + Status: corev1.ConditionFalse, + Reason: ReasonFailedResolution, + Message: err.Error(), + }) + return nil + } + if err := ValidateTaskRunAndTask(tr.Spec.Inputs.Params, rtr); err != nil { c.Logger.Error("Failed to validate taskrun %s with error %v", tr.Name, err) tr.Status.SetCondition(&duckv1alpha1.Condition{ Type: duckv1alpha1.ConditionSucceeded, diff --git a/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go b/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go index 425664e014e..2699efebe90 100644 --- a/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/taskrun_test.go @@ -615,7 +615,7 @@ func TestReconcile_InvalidTaskRuns(t *testing.T) { { name: "task run with no task", taskRun: taskRuns[0], - reason: taskrun.ReasonFailedValidation, + reason: taskrun.ReasonFailedResolution, }, } diff --git a/pkg/reconciler/v1alpha1/taskrun/validate.go b/pkg/reconciler/v1alpha1/taskrun/validate.go index c3a0ecca114..89ecef2c12f 100644 --- a/pkg/reconciler/v1alpha1/taskrun/validate.go +++ b/pkg/reconciler/v1alpha1/taskrun/validate.go @@ -20,98 +20,47 @@ import ( "fmt" "github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/taskrun/resources" ) -// validate all references in taskrun exist at runtime -func validateTaskRun(c *Reconciler, tr *v1alpha1.TaskRun) error { - // verify task reference exists, all params are provided - // and all inputs/outputs are bound - t, err := c.taskLister.Tasks(tr.Namespace).Get(tr.Spec.TaskRef.Name) - if err != nil { - return fmt.Errorf("Error listing task ref %s: %v", - tr.Spec.TaskRef.Name, err) - } - return validateTaskRunAndTask(c, *tr, t, tr.Namespace) -} - -//validateTaskRunTask validates task inputs, params and output matches taskrun -func validateTaskRunAndTask(c *Reconciler, tr v1alpha1.TaskRun, task *v1alpha1.Task, ns string) error { - // stores all the input keys to validate with task input name - inputMapping := map[string]string{} - // stores all the output keys to validate with task output name - outMapping := map[string]string{} +// ValidateTaskRunAndTask validates task inputs, params and output matches taskrun +func ValidateTaskRunAndTask(params []v1alpha1.Param, rtr *resources.ResolvedTaskRun) error { // stores params to validate with task params paramsMapping := map[string]string{} - for _, param := range tr.Spec.Inputs.Params { + for _, param := range params { paramsMapping[param.Name] = "" } - for _, source := range tr.Spec.Inputs.Resources { - inputMapping[source.Name] = "" - if source.ResourceRef.Name != "" { - rr, err := c.resourceLister.PipelineResources(ns).Get( - source.ResourceRef.Name) - if err != nil { - return fmt.Errorf("Error listing input task resource "+ - "for task %s: %v ", tr.Name, err) - } - inputMapping[source.Name] = string(rr.Spec.Type) - } - } - for _, source := range tr.Spec.Outputs.Resources { - outMapping[source.Name] = "" - if source.ResourceRef.Name != "" { - rr, err := c.resourceLister.PipelineResources(ns).Get( - source.ResourceRef.Name) - if err != nil { - return fmt.Errorf("Error listing output task resource "+ - "for task %s: %v ", tr.Name, err) - } - outMapping[source.Name] = string(rr.Spec.Type) - - } - } - - if task.Spec.Inputs != nil { - for _, inputResource := range task.Spec.Inputs.Resources { - inputResourceType, ok := inputMapping[inputResource.Name] + if rtr.Task.Spec.Inputs != nil { + for _, inputResource := range rtr.Task.Spec.Inputs.Resources { + r, ok := rtr.Inputs[inputResource.Name] if !ok { - return fmt.Errorf("Mismatch of input key %q between "+ - "task %q and task %q", inputResource.Name, - tr.Name, task.Name) + return fmt.Errorf("input resource %q not provided for task %q", inputResource.Name, rtr.Task.Name) } // Validate the type of resource match - if string(inputResource.Type) != inputResourceType { - return fmt.Errorf("Mismatch of input resource type %q "+ - "between task %q and task %q", inputResourceType, - tr.Name, task.Name) + if inputResource.Type != r.Spec.Type { + return fmt.Errorf("input resource %q for task %q should be type %q but was %q", inputResource.Name, rtr.Task.Name, r.Spec.Type, inputResource.Type) } } - for _, inputResourceParam := range task.Spec.Inputs.Params { + for _, inputResourceParam := range rtr.Task.Spec.Inputs.Params { if _, ok := paramsMapping[inputResourceParam.Name]; !ok { if inputResourceParam.Default == "" { - return fmt.Errorf("Mismatch of input params %q between "+ - "task %q and task %q", inputResourceParam.Name, tr.Name, - task.Name) + return fmt.Errorf("input param %q not provided for task %q", inputResourceParam.Name, rtr.Task.Name) } } } } - if task.Spec.Outputs != nil { - for _, outputResource := range task.Spec.Outputs.Resources { - outputResourceType, ok := outMapping[outputResource.Name] + if rtr.Task.Spec.Outputs != nil { + for _, outputResource := range rtr.Task.Spec.Outputs.Resources { + r, ok := rtr.Outputs[outputResource.Name] if !ok { - return fmt.Errorf("Mismatch of output key %q between "+ - "task %q and task %q", outputResource.Name, - tr.Name, task.Name) + return fmt.Errorf("output resource %q not provided for task %q", outputResource.Name, rtr.Task.Name) } // Validate the type of resource match - if string(outputResource.Type) != outputResourceType { - return fmt.Errorf("Mismatch of output resource type %q "+ - "between task %q and task %q", outputResourceType, - tr.Name, task.Name) + if outputResource.Type != r.Spec.Type { + return fmt.Errorf("output resource %q for task %q should be type %q but was %q", outputResource.Name, rtr.Task.Name, r.Spec.Type, outputResource.Type) } } } diff --git a/pkg/reconciler/v1alpha1/taskrun/validate_test.go b/pkg/reconciler/v1alpha1/taskrun/validate_test.go index 3c6fd1bd1ad..2156570e43f 100644 --- a/pkg/reconciler/v1alpha1/taskrun/validate_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/validate_test.go @@ -1,13 +1,11 @@ package taskrun_test import ( - "context" - "fmt" "testing" "github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/knative/build-pipeline/test" - duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1" + "github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/taskrun" + "github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/taskrun/resources" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -18,48 +16,103 @@ var validBuildSteps = []corev1.Container{{ Command: []string{"mycmd"}, }} -func Test_ValidTaskRunTask(t *testing.T) { - trs := []*v1alpha1.TaskRun{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "taskrun-valid-input", - Namespace: "foo", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: v1alpha1.TaskRef{ - Name: "task-valid-input", - }, - Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResource{ - v1alpha1.TaskRunResource{ +func TestValidateTaskRunAndTask(t *testing.T) { + rtr := &resources.ResolvedTaskRun{ + Task: &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "task-valid-input", + Namespace: "foo", + }, + Spec: v1alpha1.TaskSpec{ + Steps: validBuildSteps, + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ Name: "resource-to-build", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "example-resource", - }, - }, + Type: v1alpha1.PipelineResourceTypeGit, + }}, }, - }, - }, + }}, + Inputs: map[string]*v1alpha1.PipelineResource{ + "resource-to-build": &v1alpha1.PipelineResource{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example-resource", + Namespace: "foo", + }, + Spec: v1alpha1.PipelineResourceSpec{ + Type: v1alpha1.PipelineResourceTypeGit, + Params: []v1alpha1.Param{{ + Name: "foo", + Value: "bar", + }}, + }, + }}, + } + if err := taskrun.ValidateTaskRunAndTask([]v1alpha1.Param{}, rtr); err != nil { + t.Fatalf("Did not expect to see error when validating valid resolved TaskRun but saw %v", err) + } +} + +func Test_ValidParams(t *testing.T) { + rtr := &resources.ResolvedTaskRun{ + Task: &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "unit-task-multiple-params", + Namespace: "foo", + }, + Spec: v1alpha1.TaskSpec{ + Steps: validBuildSteps, + Inputs: &v1alpha1.Inputs{ + Params: []v1alpha1.TaskParam{{ + Name: "foo", + }, { + Name: "bar", + }}, + }, + }}, + } + p := []v1alpha1.Param{{ + Name: "foo", + Value: "somethinggood", + }, { + Name: "bar", + Value: "somethinggood", }} + if err := taskrun.ValidateTaskRunAndTask(p, rtr); err != nil { + t.Fatalf("Did not expect to see error when validating TaskRun with correct params but saw %v", err) + } +} - ts := []*v1alpha1.Task{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "task-valid-input", - Namespace: "foo", - }, - Spec: v1alpha1.TaskSpec{ - Steps: validBuildSteps, - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - Name: "resource-to-build", - Type: v1alpha1.PipelineResourceTypeGit, - }}, - }, - }, +func Test_InvalidParams(t *testing.T) { + rtr := &resources.ResolvedTaskRun{ + Task: &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "unit-task-multiple-params", + Namespace: "foo", + }, + Spec: v1alpha1.TaskSpec{ + Steps: validBuildSteps, + Inputs: &v1alpha1.Inputs{ + Params: []v1alpha1.TaskParam{{ + Name: "foo", + }, { + Name: "bar", + }}, + }, + }}, + } + p := []v1alpha1.Param{{ + Name: "foobar", + Value: "somethingfun", }} + if err := taskrun.ValidateTaskRunAndTask(p, rtr); err == nil { + t.Errorf("Expected to see error when validating invalid resolved TaskRun with wrong params but saw none") + } +} - rr := []*v1alpha1.PipelineResource{{ +func Test_InvalidTaskRunTask(t *testing.T) { + r := &v1alpha1.PipelineResource{ ObjectMeta: metav1.ObjectMeta{ - Name: "example-resource", + Name: "git-test-resource", Namespace: "foo", }, Spec: v1alpha1.PipelineResourceSpec{ @@ -69,288 +122,86 @@ func Test_ValidTaskRunTask(t *testing.T) { Value: "bar", }}, }, - }} - + } tcs := []struct { - name string - taskrun *v1alpha1.TaskRun - reason string + name string + rtr *resources.ResolvedTaskRun }{{ - name: "taskrun-valid-input", - taskrun: trs[0], - reason: "taskrun-with-valid-inputs", - }} - - for i, tc := range tcs { - t.Run(tc.name, func(t *testing.T) { - d := test.Data{ - TaskRuns: []*v1alpha1.TaskRun{trs[i]}, - Tasks: ts, - PipelineResources: rr, - } - - c, _, _ := test.GetTaskRunController(d) - err := c.Reconciler.Reconcile(context.Background(), - fmt.Sprintf("%s/%s", tc.taskrun.Namespace, tc.taskrun.Name)) - - if err != nil { - t.Errorf("Did not expect to see error when reconciling invalid task but saw %q", err) - } - condition := trs[i].Status.GetCondition(duckv1alpha1.ConditionSucceeded) - if condition == nil || condition.Status == corev1.ConditionFalse { - t.Errorf("Valid task %s failed with condition %s, expected no failure", tc.taskrun.Name, condition) - } - }) - } -} - -func Test_InvalidTaskRunTask(t *testing.T) { - trs := []*v1alpha1.TaskRun{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-bad-task-input-resourceref", - Namespace: "foo", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: v1alpha1.TaskRef{ - Name: "unit-test-task", - }, - Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResource{ - v1alpha1.TaskRunResource{ - Name: "test-resource-name", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "non-existent-resource1", - }, - }, + name: "bad-inputkey", + rtr: &resources.ResolvedTaskRun{ + Task: &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "unit-task-wrong-input", + Namespace: "foo", }, - }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-bad-task-output-resourceref", - Namespace: "foo", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: v1alpha1.TaskRef{ - Name: "unit-test-task", - }, - Outputs: v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskRunResource{ - v1alpha1.TaskRunResource{ - Name: "test-resource-name", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "non-existent-resource1", - }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + Name: "testinput", + }}, }, }, }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-bad-inputkey", - Namespace: "foo", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: v1alpha1.TaskRef{ - Name: "unit-test-wrong-input", - }, - Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResource{ - v1alpha1.TaskRunResource{ - Name: "test-resource-name", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "non-existent", - }, - }, + Inputs: map[string]*v1alpha1.PipelineResource{"wrong-resource-name": r}, + }}, { + name: "bad-outputkey", + rtr: &resources.ResolvedTaskRun{ + Task: &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "unit-task-wrong-output", + Namespace: "foo", }, - }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-bad-outputkey", - Namespace: "foo", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: v1alpha1.TaskRef{ - Name: "unit-test-task", - }, - Outputs: v1alpha1.TaskRunOutputs{ - Resources: []v1alpha1.TaskRunResource{ - v1alpha1.TaskRunResource{ - Name: "test-resource-name", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "non-existent", - }, + Spec: v1alpha1.TaskSpec{ + Outputs: &v1alpha1.Outputs{ + Resources: []v1alpha1.TaskResource{{ + Name: "testoutput", + }}, }, }, }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-param-mismatch", - Namespace: "foo", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: v1alpha1.TaskRef{ - Name: "unit-task-multiple-params", - }, - Inputs: v1alpha1.TaskRunInputs{ - Params: []v1alpha1.Param{ - v1alpha1.Param{ - Name: "foobar", - Value: "somethingfun", + Outputs: map[string]*v1alpha1.PipelineResource{"wrong-resource-name": r}, + }}, { + name: "input-resource-mismatch", + rtr: &resources.ResolvedTaskRun{ + Task: &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "unit-task-bad-input-resourcetype", + Namespace: "foo", + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + Name: "testimageinput", + Type: v1alpha1.PipelineResourceTypeImage, + }}, }, }, }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-bad-resourcetype", - Namespace: "foo", - }, - Spec: v1alpha1.TaskRunSpec{ - TaskRef: v1alpha1.TaskRef{ - Name: "unit-task-bad-resourcetype", - }, - Inputs: v1alpha1.TaskRunInputs{ - Resources: []v1alpha1.TaskRunResource{ - v1alpha1.TaskRunResource{ - Name: "testimageinput", - ResourceRef: v1alpha1.PipelineResourceRef{ - Name: "git-test-resource", - }, + Inputs: map[string]*v1alpha1.PipelineResource{"testimageinput": r}, + }}, { + name: "output-resource-mismatch", + rtr: &resources.ResolvedTaskRun{ + Task: &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "unit-task-bad-output-resourcetype", + Namespace: "foo", + }, + Spec: v1alpha1.TaskSpec{ + Outputs: &v1alpha1.Outputs{ + Resources: []v1alpha1.TaskResource{{ + Name: "testimageoutput", + Type: v1alpha1.PipelineResourceTypeImage, + }}, }, }, }, - }, - }} + Outputs: map[string]*v1alpha1.PipelineResource{"testimageoutput": r}, + }}} - ts := []*v1alpha1.Task{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "unit-test-task", - Namespace: "foo", - }, - Spec: v1alpha1.TaskSpec{ - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{}}, - }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "unit-task-wrong-input", - Namespace: "foo", - }, - Spec: v1alpha1.TaskSpec{ - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - Name: "testinput", - }}, - }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "unit-task-wrong-output", - Namespace: "foo", - }, - Spec: v1alpha1.TaskSpec{ - Outputs: &v1alpha1.Outputs{ - Resources: []v1alpha1.TaskResource{{ - Name: "testoutput", - }}, - }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "unit-task-multiple-params", - Namespace: "foo", - }, - Spec: v1alpha1.TaskSpec{ - Inputs: &v1alpha1.Inputs{ - Params: []v1alpha1.TaskParam{{ - Name: "foo", - }, { - Name: "bar", - }}, - }, - }, - }, { - ObjectMeta: metav1.ObjectMeta{ - Name: "unit-task-bad-resourcetype", - Namespace: "foo", - }, - Spec: v1alpha1.TaskSpec{ - Inputs: &v1alpha1.Inputs{ - Resources: []v1alpha1.TaskResource{{ - Name: "testimageinput", - Type: v1alpha1.PipelineResourceTypeImage, - }}, - }, - }, - }} - - rr := []*v1alpha1.PipelineResource{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "git-test-resource", - Namespace: "foo", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.Param{{ - Name: "foo", - Value: "bar", - }}, - }, - }} - - tcs := []struct { - name string - taskrun *v1alpha1.TaskRun - reason string - }{ - { - name: "bad-input-source-bindings", - taskrun: trs[0], - reason: "input-source-binding-to-invalid-resource", - }, { - name: "bad-output-source-bindings", - taskrun: trs[1], - reason: "output-source-binding-to-invalid-resource", - }, { - name: "bad-inputkey", - taskrun: trs[2], - reason: "bad-input-mapping", - }, { - name: "bad-outputkey", - taskrun: trs[3], - reason: "bad-output-mapping", - }, { - name: "param-mismatch", - taskrun: trs[4], - reason: "input-param-mismatch", - }, { - name: "resource-mismatch", - taskrun: trs[5], - reason: "input-resource-mismatch", - }} - - for i, tc := range tcs { + for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - d := test.Data{ - TaskRuns: []*v1alpha1.TaskRun{trs[i]}, - Tasks: ts, - PipelineResources: rr, - } - - c, _, _ := test.GetTaskRunController(d) - err := c.Reconciler.Reconcile(context.Background(), - fmt.Sprintf("%s/%s", tc.taskrun.Namespace, tc.taskrun.Name)) - - if err != nil { - t.Errorf("Did not expect to see error when reconciling invalid task but saw %q", err) - } - condition := trs[i].Status.GetCondition(duckv1alpha1.ConditionSucceeded) - if condition == nil || condition.Status != corev1.ConditionFalse { - t.Errorf("Expected status to be failed on invalid task %s but was: %v", tc.taskrun.Name, condition) + if err := taskrun.ValidateTaskRunAndTask([]v1alpha1.Param{}, tc.rtr); err == nil { + t.Errorf("Expected to see error when validating invalid resolved TaskRun but saw none") } }) }