Skip to content

Commit

Permalink
fix: value is required when parameter is of type enum (#9753)
Browse files Browse the repository at this point in the history
* fix: `value` is required when parameter is of type
`enum`

Without this change we get error:
`Recovered from panic: runtime error: invalid memory address or nil pointer dereference`

Signed-off-by: Ricardo Rosales <728243+missingcharacter@users.noreply.github.com>

* fix: Adding test TestWorkflowTemplateWithEnumValueWithoutValue

Signed-off-by: Ricardo Rosales <728243+missingcharacter@users.noreply.github.com>

Signed-off-by: Ricardo Rosales <728243+missingcharacter@users.noreply.github.com>
  • Loading branch information
missingcharacter authored Oct 6, 2022
1 parent 2312cc9 commit de4ea2d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ func validateArgumentsValues(prefix string, arguments wfv1.Arguments, allowEmpty
if len(param.Enum) == 0 {
return errors.Errorf(errors.CodeBadRequest, "%s%s.enum should contain at least one value", prefix, param.Name)
}
if param.Value == nil {
return errors.Errorf(errors.CodeBadRequest, "%s%s.value is required", prefix, param.Name)
}
valueSpecifiedInEnumList := false
for _, enum := range param.Enum {
if enum == *param.Value {
Expand Down
41 changes: 41 additions & 0 deletions workflow/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,38 @@ spec:
- '{{inputs.parameters.message}}'
`

var workflowTeamplateWithEnumValuesWithoutValue = `
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
generateName: test-enum-1-
labels:
testLabel: foobar
spec:
entrypoint: argosay
arguments:
parameters:
- name: message
enum:
- one
- two
- three
templates:
- name: argosay
inputs:
parameters:
- name: message
value: '{{workflow.parameters.message}}'
container:
name: main
image: 'argoproj/argosay:v2'
command:
- /argosay
args:
- echo
- '{{inputs.parameters.message}}'
`

func TestWorkflowTemplateWithEnumValue(t *testing.T) {
err := validateWorkflowTemplate(workflowTeamplateWithEnumValues, ValidateOpts{})
assert.NoError(t, err)
Expand Down Expand Up @@ -2521,6 +2553,15 @@ func TestWorkflowTemplateWithArgumentValueNotFromEnumList(t *testing.T) {
assert.EqualError(t, err, "spec.arguments.message.value should be present in spec.arguments.message.enum list")
}

func TestWorkflowTemplateWithEnumValueWithoutValue(t *testing.T) {
err := validateWorkflowTemplate(workflowTeamplateWithEnumValuesWithoutValue, ValidateOpts{})
assert.EqualError(t, err, "spec.arguments.message.value is required")
err = validateWorkflowTemplate(workflowTeamplateWithEnumValuesWithoutValue, ValidateOpts{Lint: true})
assert.EqualError(t, err, "spec.arguments.message.value is required")
err = validateWorkflowTemplate(workflowTeamplateWithEnumValuesWithoutValue, ValidateOpts{Submit: true})
assert.EqualError(t, err, "spec.arguments.message.value is required")
}

var validActiveDeadlineSecondsArgoVariable = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
Expand Down

0 comments on commit de4ea2d

Please sign in to comment.