From 8406e46cfeb0cffa5dc7dd02a4ffc8f2e2823ea3 Mon Sep 17 00:00:00 2001 From: Lee Bernick Date: Wed, 17 May 2023 12:08:01 -0400 Subject: [PATCH] Test refactor: separate Task validation tests for propagation To support propagated parameters in inline Task specs, validation of variable usage is skipped for inline Task specs and performed only for referenced Tasks. This commit refactors TestTaskSpecValidateError to split out the test cases which rely on this validation logic from test cases that rely on validation logic that is always performed. Since validation logic for usage of declared variables should always be performed when a Task is created directly (but not always for a Task spec), it updates these tests to validate a Task rather than a Task spec. This refactoring will make cleanup for propagated parameters easier. No functional changes. --- pkg/apis/pipeline/v1/task_validation_test.go | 383 ++++++++++-------- .../pipeline/v1beta1/task_validation_test.go | 383 ++++++++++-------- 2 files changed, 416 insertions(+), 350 deletions(-) diff --git a/pkg/apis/pipeline/v1/task_validation_test.go b/pkg/apis/pipeline/v1/task_validation_test.go index ef5cb58412b..d625b794308 100644 --- a/pkg/apis/pipeline/v1/task_validation_test.go +++ b/pkg/apis/pipeline/v1/task_validation_test.go @@ -522,6 +522,214 @@ func TestTaskSpecValidate(t *testing.T) { } } +func TestTaskValidateError(t *testing.T) { + type fields struct { + Params []v1.ParamSpec + Steps []v1.Step + } + tests := []struct { + name string + fields fields + expectedError apis.FieldError + }{{ + name: "inexistent param variable", + fields: fields{ + Steps: []v1.Step{{ + Name: "mystep", + Image: "myimage", + Args: []string{"--flag=$(params.inexistent)"}, + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "--flag=$(params.inexistent)"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "object used in a string field", + fields: fields{ + Params: []v1.ParamSpec{{ + Name: "gitrepo", + Type: v1.ParamTypeObject, + Properties: map[string]v1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1.Step{{ + Name: "do-the-clone", + Image: "$(params.gitrepo)", + Args: []string{"echo"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `variable type invalid in "$(params.gitrepo)"`, + Paths: []string{"spec.steps[0].image"}, + }, + }, { + name: "object star used in a string field", + fields: fields{ + Params: []v1.ParamSpec{{ + Name: "gitrepo", + Type: v1.ParamTypeObject, + Properties: map[string]v1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1.Step{{ + Name: "do-the-clone", + Image: "$(params.gitrepo[*])", + Args: []string{"echo"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `variable type invalid in "$(params.gitrepo[*])"`, + Paths: []string{"spec.steps[0].image"}, + }, + }, { + name: "object used in a field that can accept array type", + fields: fields{ + Params: []v1.ParamSpec{{ + Name: "gitrepo", + Type: v1.ParamTypeObject, + Properties: map[string]v1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1.Step{{ + Name: "do-the-clone", + Image: "myimage", + Args: []string{"$(params.gitrepo)"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `variable type invalid in "$(params.gitrepo)"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "object star used in a field that can accept array type", + fields: fields{ + Params: []v1.ParamSpec{{ + Name: "gitrepo", + Type: v1.ParamTypeObject, + Properties: map[string]v1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1.Step{{ + Name: "do-the-clone", + Image: "some-git-image", + Args: []string{"$(params.gitrepo[*])"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `variable type invalid in "$(params.gitrepo[*])"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "non-existent individual key of an object param is used in task step", + fields: fields{ + Params: []v1.ParamSpec{{ + Name: "gitrepo", + Type: v1.ParamTypeObject, + Properties: map[string]v1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1.Step{{ + Name: "do-the-clone", + Image: "some-git-image", + Args: []string{"$(params.gitrepo.non-exist-key)"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "$(params.gitrepo.non-exist-key)"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "Inexistent param variable in volumeMount with existing", + fields: fields{ + Params: []v1.ParamSpec{ + { + Name: "foo", + Description: "param", + Default: v1.NewStructuredValues("default"), + }, + }, + Steps: []v1.Step{{ + Name: "mystep", + Image: "myimage", + VolumeMounts: []corev1.VolumeMount{{ + Name: "$(params.inexistent)-foo", + }}, + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "$(params.inexistent)-foo"`, + Paths: []string{"spec.steps[0].volumeMount[0].name"}, + }, + }, { + name: "Inexistent param variable with existing", + fields: fields{ + Params: []v1.ParamSpec{{ + Name: "foo", + Description: "param", + Default: v1.NewStructuredValues("default"), + }}, + Steps: []v1.Step{{ + Name: "mystep", + Image: "myimage", + Args: []string{"$(params.foo) && $(params.inexistent)"}, + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "$(params.foo) && $(params.inexistent)"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "invalid step - invalid onError usage - set to a parameter which does not exist in the task", + fields: fields{ + Steps: []v1.Step{{ + OnError: "$(params.CONTINUE)", + Image: "image", + Args: []string{"arg"}, + }}, + }, + expectedError: apis.FieldError{ + Message: "non-existent variable in \"$(params.CONTINUE)\"", + Paths: []string{"spec.steps[0].onError"}, + }, + }} + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + task := &v1.Task{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Spec: v1.TaskSpec{ + Params: tt.fields.Params, + Steps: tt.fields.Steps, + }} + ctx := config.EnableAlphaAPIFields(context.Background()) + task.SetDefaults(ctx) + ctx = config.SkipValidationDueToPropagatedParametersAndWorkspaces(ctx, false) + err := task.Validate(ctx) + if err == nil { + t.Fatalf("Expected an error, got nothing for %v", task) + } + if d := cmp.Diff(tt.expectedError.Error(), err.Error(), cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" { + t.Errorf("TaskSpec.Validate() errors diff %s", diff.PrintWantGot(d)) + } + }) + } +} + func TestTaskSpecValidateError(t *testing.T) { type fields struct { Params []v1.ParamSpec @@ -767,19 +975,6 @@ func TestTaskSpecValidateError(t *testing.T) { Paths: []string{"steps[0].name"}, Details: "Task step name must be a valid DNS Label, For more info refer to https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names", }, - }, { - name: "inexistent param variable", - fields: fields{ - Steps: []v1.Step{{ - Name: "mystep", - Image: "myimage", - Args: []string{"--flag=$(params.inexistent)"}, - }}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "--flag=$(params.inexistent)"`, - Paths: []string{"steps[0].args[0]"}, - }, }, { name: "array used in unaccepted field", fields: fields{ @@ -934,156 +1129,6 @@ func TestTaskSpecValidateError(t *testing.T) { Message: `variable is not properly isolated in "not isolated: $(params.baz[*])"`, Paths: []string{"steps[0].args[0]"}, }, - }, { - name: "object used in a string field", - fields: fields{ - Params: []v1.ParamSpec{{ - Name: "gitrepo", - Type: v1.ParamTypeObject, - Properties: map[string]v1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1.Step{{ - Name: "do-the-clone", - Image: "$(params.gitrepo)", - Args: []string{"echo"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `variable type invalid in "$(params.gitrepo)"`, - Paths: []string{"steps[0].image"}, - }, - }, { - name: "object star used in a string field", - fields: fields{ - Params: []v1.ParamSpec{{ - Name: "gitrepo", - Type: v1.ParamTypeObject, - Properties: map[string]v1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1.Step{{ - Name: "do-the-clone", - Image: "$(params.gitrepo[*])", - Args: []string{"echo"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `variable type invalid in "$(params.gitrepo[*])"`, - Paths: []string{"steps[0].image"}, - }, - }, { - name: "object used in a field that can accept array type", - fields: fields{ - Params: []v1.ParamSpec{{ - Name: "gitrepo", - Type: v1.ParamTypeObject, - Properties: map[string]v1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1.Step{{ - Name: "do-the-clone", - Image: "myimage", - Args: []string{"$(params.gitrepo)"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `variable type invalid in "$(params.gitrepo)"`, - Paths: []string{"steps[0].args[0]"}, - }, - }, { - name: "object star used in a field that can accept array type", - fields: fields{ - Params: []v1.ParamSpec{{ - Name: "gitrepo", - Type: v1.ParamTypeObject, - Properties: map[string]v1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1.Step{{ - Name: "do-the-clone", - Image: "some-git-image", - Args: []string{"$(params.gitrepo[*])"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `variable type invalid in "$(params.gitrepo[*])"`, - Paths: []string{"steps[0].args[0]"}, - }, - }, { - name: "non-existent individual key of an object param is used in task step", - fields: fields{ - Params: []v1.ParamSpec{{ - Name: "gitrepo", - Type: v1.ParamTypeObject, - Properties: map[string]v1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1.Step{{ - Name: "do-the-clone", - Image: "some-git-image", - Args: []string{"$(params.gitrepo.non-exist-key)"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "$(params.gitrepo.non-exist-key)"`, - Paths: []string{"steps[0].args[0]"}, - }, - }, { - name: "Inexistent param variable in volumeMount with existing", - fields: fields{ - Params: []v1.ParamSpec{ - { - Name: "foo", - Description: "param", - Default: v1.NewStructuredValues("default"), - }, - }, - Steps: []v1.Step{{ - Name: "mystep", - Image: "myimage", - VolumeMounts: []corev1.VolumeMount{{ - Name: "$(params.inexistent)-foo", - }}, - }}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "$(params.inexistent)-foo"`, - Paths: []string{"steps[0].volumeMount[0].name"}, - }, - }, { - name: "Inexistent param variable with existing", - fields: fields{ - Params: []v1.ParamSpec{{ - Name: "foo", - Description: "param", - Default: v1.NewStructuredValues("default"), - }}, - Steps: []v1.Step{{ - Name: "mystep", - Image: "myimage", - Args: []string{"$(params.foo) && $(params.inexistent)"}, - }}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "$(params.foo) && $(params.inexistent)"`, - Paths: []string{"steps[0].args[0]"}, - }, }, { name: "Multiple volumes with same name", fields: fields{ @@ -1317,7 +1362,6 @@ func TestTaskSpecValidateError(t *testing.T) { } ctx := config.EnableAlphaAPIFields(context.Background()) ts.SetDefaults(ctx) - ctx = config.SkipValidationDueToPropagatedParametersAndWorkspaces(ctx, false) err := ts.Validate(ctx) if err == nil { t.Fatalf("Expected an error, got nothing for %v", ts) @@ -1515,17 +1559,6 @@ func TestStepOnError(t *testing.T) { Paths: []string{"steps[0].onError"}, Details: `Task step onError must be either "continue" or "stopAndFail"`, }, - }, { - name: "invalid step - invalid onError usage - set to a parameter which does not exist in the task", - steps: []v1.Step{{ - OnError: "$(params.CONTINUE)", - Image: "image", - Args: []string{"arg"}, - }}, - expectedError: &apis.FieldError{ - Message: "non-existent variable in \"$(params.CONTINUE)\"", - Paths: []string{"steps[0].onError"}, - }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/apis/pipeline/v1beta1/task_validation_test.go b/pkg/apis/pipeline/v1beta1/task_validation_test.go index 3256d99db02..1d48e0227c8 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/task_validation_test.go @@ -525,6 +525,214 @@ func TestTaskSpecValidate(t *testing.T) { } } +func TestTaskValidateError(t *testing.T) { + type fields struct { + Params []v1beta1.ParamSpec + Steps []v1beta1.Step + } + tests := []struct { + name string + fields fields + expectedError apis.FieldError + }{{ + name: "inexistent param variable", + fields: fields{ + Steps: []v1beta1.Step{{ + Name: "mystep", + Image: "myimage", + Args: []string{"--flag=$(params.inexistent)"}, + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "--flag=$(params.inexistent)"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "object used in a string field", + fields: fields{ + Params: []v1beta1.ParamSpec{{ + Name: "gitrepo", + Type: v1beta1.ParamTypeObject, + Properties: map[string]v1beta1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1beta1.Step{{ + Name: "do-the-clone", + Image: "$(params.gitrepo)", + Args: []string{"echo"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `variable type invalid in "$(params.gitrepo)"`, + Paths: []string{"spec.steps[0].image"}, + }, + }, { + name: "object star used in a string field", + fields: fields{ + Params: []v1beta1.ParamSpec{{ + Name: "gitrepo", + Type: v1beta1.ParamTypeObject, + Properties: map[string]v1beta1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1beta1.Step{{ + Name: "do-the-clone", + Image: "$(params.gitrepo[*])", + Args: []string{"echo"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `variable type invalid in "$(params.gitrepo[*])"`, + Paths: []string{"spec.steps[0].image"}, + }, + }, { + name: "object used in a field that can accept array type", + fields: fields{ + Params: []v1beta1.ParamSpec{{ + Name: "gitrepo", + Type: v1beta1.ParamTypeObject, + Properties: map[string]v1beta1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1beta1.Step{{ + Name: "do-the-clone", + Image: "myimage", + Args: []string{"$(params.gitrepo)"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `variable type invalid in "$(params.gitrepo)"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "object star used in a field that can accept array type", + fields: fields{ + Params: []v1beta1.ParamSpec{{ + Name: "gitrepo", + Type: v1beta1.ParamTypeObject, + Properties: map[string]v1beta1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1beta1.Step{{ + Name: "do-the-clone", + Image: "some-git-image", + Args: []string{"$(params.gitrepo[*])"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `variable type invalid in "$(params.gitrepo[*])"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "non-existent individual key of an object param is used in task step", + fields: fields{ + Params: []v1beta1.ParamSpec{{ + Name: "gitrepo", + Type: v1beta1.ParamTypeObject, + Properties: map[string]v1beta1.PropertySpec{ + "url": {}, + "commit": {}, + }, + }}, + Steps: []v1beta1.Step{{ + Name: "do-the-clone", + Image: "some-git-image", + Args: []string{"$(params.gitrepo.non-exist-key)"}, + WorkingDir: "/foo/bar/src/", + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "$(params.gitrepo.non-exist-key)"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "Inexistent param variable in volumeMount with existing", + fields: fields{ + Params: []v1beta1.ParamSpec{ + { + Name: "foo", + Description: "param", + Default: v1beta1.NewStructuredValues("default"), + }, + }, + Steps: []v1beta1.Step{{ + Name: "mystep", + Image: "myimage", + VolumeMounts: []corev1.VolumeMount{{ + Name: "$(params.inexistent)-foo", + }}, + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "$(params.inexistent)-foo"`, + Paths: []string{"spec.steps[0].volumeMount[0].name"}, + }, + }, { + name: "Inexistent param variable with existing", + fields: fields{ + Params: []v1beta1.ParamSpec{{ + Name: "foo", + Description: "param", + Default: v1beta1.NewStructuredValues("default"), + }}, + Steps: []v1beta1.Step{{ + Name: "mystep", + Image: "myimage", + Args: []string{"$(params.foo) && $(params.inexistent)"}, + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "$(params.foo) && $(params.inexistent)"`, + Paths: []string{"spec.steps[0].args[0]"}, + }, + }, { + name: "invalid step - invalid onError usage - set to a parameter which does not exist in the task", + fields: fields{ + Steps: []v1beta1.Step{{ + OnError: "$(params.CONTINUE)", + Image: "image", + Args: []string{"arg"}, + }}, + }, + expectedError: apis.FieldError{ + Message: `non-existent variable in "$(params.CONTINUE)"`, + Paths: []string{"spec.steps[0].onError"}, + }, + }} + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + task := &v1beta1.Task{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Spec: v1beta1.TaskSpec{ + Params: tt.fields.Params, + Steps: tt.fields.Steps, + }} + ctx := config.EnableAlphaAPIFields(context.Background()) + task.SetDefaults(ctx) + ctx = config.SkipValidationDueToPropagatedParametersAndWorkspaces(ctx, false) + err := task.Validate(ctx) + if err == nil { + t.Fatalf("Expected an error, got nothing for %v", task) + } + if d := cmp.Diff(tt.expectedError.Error(), err.Error(), cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" { + t.Errorf("TaskSpec.Validate() errors diff %s", diff.PrintWantGot(d)) + } + }) + } +} + func TestTaskSpecValidateError(t *testing.T) { type fields struct { Params []v1beta1.ParamSpec @@ -771,19 +979,6 @@ func TestTaskSpecValidateError(t *testing.T) { Paths: []string{"steps[0].name"}, Details: "Task step name must be a valid DNS Label, For more info refer to https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names", }, - }, { - name: "inexistent param variable", - fields: fields{ - Steps: []v1beta1.Step{{ - Name: "mystep", - Image: "myimage", - Args: []string{"--flag=$(params.inexistent)"}, - }}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "--flag=$(params.inexistent)"`, - Paths: []string{"steps[0].args[0]"}, - }, }, { name: "array used in unaccepted field", fields: fields{ @@ -938,156 +1133,6 @@ func TestTaskSpecValidateError(t *testing.T) { Message: `variable is not properly isolated in "not isolated: $(params.baz[*])"`, Paths: []string{"steps[0].args[0]"}, }, - }, { - name: "object used in a string field", - fields: fields{ - Params: []v1beta1.ParamSpec{{ - Name: "gitrepo", - Type: v1beta1.ParamTypeObject, - Properties: map[string]v1beta1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1beta1.Step{{ - Name: "do-the-clone", - Image: "$(params.gitrepo)", - Args: []string{"echo"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `variable type invalid in "$(params.gitrepo)"`, - Paths: []string{"steps[0].image"}, - }, - }, { - name: "object star used in a string field", - fields: fields{ - Params: []v1beta1.ParamSpec{{ - Name: "gitrepo", - Type: v1beta1.ParamTypeObject, - Properties: map[string]v1beta1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1beta1.Step{{ - Name: "do-the-clone", - Image: "$(params.gitrepo[*])", - Args: []string{"echo"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `variable type invalid in "$(params.gitrepo[*])"`, - Paths: []string{"steps[0].image"}, - }, - }, { - name: "object used in a field that can accept array type", - fields: fields{ - Params: []v1beta1.ParamSpec{{ - Name: "gitrepo", - Type: v1beta1.ParamTypeObject, - Properties: map[string]v1beta1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1beta1.Step{{ - Name: "do-the-clone", - Image: "myimage", - Args: []string{"$(params.gitrepo)"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `variable type invalid in "$(params.gitrepo)"`, - Paths: []string{"steps[0].args[0]"}, - }, - }, { - name: "object star used in a field that can accept array type", - fields: fields{ - Params: []v1beta1.ParamSpec{{ - Name: "gitrepo", - Type: v1beta1.ParamTypeObject, - Properties: map[string]v1beta1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1beta1.Step{{ - Name: "do-the-clone", - Image: "some-git-image", - Args: []string{"$(params.gitrepo[*])"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `variable type invalid in "$(params.gitrepo[*])"`, - Paths: []string{"steps[0].args[0]"}, - }, - }, { - name: "non-existent individual key of an object param is used in task step", - fields: fields{ - Params: []v1beta1.ParamSpec{{ - Name: "gitrepo", - Type: v1beta1.ParamTypeObject, - Properties: map[string]v1beta1.PropertySpec{ - "url": {}, - "commit": {}, - }, - }}, - Steps: []v1beta1.Step{{ - Name: "do-the-clone", - Image: "some-git-image", - Args: []string{"$(params.gitrepo.non-exist-key)"}, - WorkingDir: "/foo/bar/src/", - }}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "$(params.gitrepo.non-exist-key)"`, - Paths: []string{"steps[0].args[0]"}, - }, - }, { - name: "Inexistent param variable in volumeMount with existing", - fields: fields{ - Params: []v1beta1.ParamSpec{ - { - Name: "foo", - Description: "param", - Default: v1beta1.NewStructuredValues("default"), - }, - }, - Steps: []v1beta1.Step{{ - Name: "mystep", - Image: "myimage", - VolumeMounts: []corev1.VolumeMount{{ - Name: "$(params.inexistent)-foo", - }}, - }}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "$(params.inexistent)-foo"`, - Paths: []string{"steps[0].volumeMount[0].name"}, - }, - }, { - name: "Inexistent param variable with existing", - fields: fields{ - Params: []v1beta1.ParamSpec{{ - Name: "foo", - Description: "param", - Default: v1beta1.NewStructuredValues("default"), - }}, - Steps: []v1beta1.Step{{ - Name: "mystep", - Image: "myimage", - Args: []string{"$(params.foo) && $(params.inexistent)"}, - }}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "$(params.foo) && $(params.inexistent)"`, - Paths: []string{"steps[0].args[0]"}, - }, }, { name: "Multiple volumes with same name", fields: fields{ @@ -1329,7 +1374,6 @@ func TestTaskSpecValidateError(t *testing.T) { } ctx := config.EnableAlphaAPIFields(context.Background()) ts.SetDefaults(ctx) - ctx = config.SkipValidationDueToPropagatedParametersAndWorkspaces(ctx, false) err := ts.Validate(ctx) if err == nil { t.Fatalf("Expected an error, got nothing for %v", ts) @@ -1527,17 +1571,6 @@ func TestStepOnError(t *testing.T) { Paths: []string{"steps[0].onError"}, Details: `Task step onError must be either "continue" or "stopAndFail"`, }, - }, { - name: "invalid step - invalid onError usage - set to a parameter which does not exist in the task", - steps: []v1beta1.Step{{ - OnError: "$(params.CONTINUE)", - Image: "image", - Args: []string{"arg"}, - }}, - expectedError: &apis.FieldError{ - Message: `non-existent variable in "$(params.CONTINUE)"`, - Paths: []string{"steps[0].onError"}, - }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {