Skip to content

Commit

Permalink
fix: sensor controller validate sensor (#1378)
Browse files Browse the repository at this point in the history
Signed-off-by: luca-iachini <[email protected]>
  • Loading branch information
luca-iachini authored Oct 14, 2021
1 parent 790ab8d commit 79c472d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions controllers/sensor/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func validateTriggers(triggers []v1alpha1.Trigger) error {
trigNames := make(map[string]bool)

for _, trigger := range triggers {
if err := validateTriggerTemplate(trigger.Template); err != nil {
return err
}
if _, ok := trigNames[trigger.Template.Name]; ok {
return fmt.Errorf("duplicate trigger name: %s", trigger.Template.Name)
}
trigNames[trigger.Template.Name] = true
if err := validateTriggerTemplate(trigger.Template); err != nil {
return err
}
if err := validateTriggerPolicy(&trigger); err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions controllers/sensor/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,15 @@ func TestValidTriggers(t *testing.T) {
assert.NotNil(t, err)
assert.Equal(t, true, strings.Contains(err.Error(), "duplicate trigger name:"))
})

t.Run("empty trigger template", func(t *testing.T) {
triggers := []v1alpha1.Trigger{
{
Template: nil,
},
}
err := validateTriggers(triggers)
assert.NotNil(t, err)
assert.Equal(t, true, strings.Contains(err.Error(), "trigger template can't be nil"))
})
}

0 comments on commit 79c472d

Please sign in to comment.