Fix regression in removing notification (#5673)

fixes a regression introduced in 0e4431725c
when removing a previously applied notification configuration.

event.ParseConfig() was stricter in terms of handling notification
configuration, we need to allow when notification configuration is
sent empty, this is the way to remove notification configuration.
master
Harshavardhana 7 years ago committed by kannappanr
parent b4ae2bd2f5
commit c726145baf
  1. 19
      pkg/event/config.go
  2. 5
      pkg/event/config_test.go

@ -219,14 +219,13 @@ func (conf *Config) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return err
}
if len(parsedConfig.QueueList) == 0 {
return errors.New("missing queue configuration(s)")
}
for i, q1 := range parsedConfig.QueueList[:len(parsedConfig.QueueList)-1] {
for _, q2 := range parsedConfig.QueueList[i+1:] {
if reflect.DeepEqual(q1, q2) {
return &ErrDuplicateQueueConfiguration{q1}
// Empty queue list means user wants to delete the notification configuration.
if len(parsedConfig.QueueList) > 0 {
for i, q1 := range parsedConfig.QueueList[:len(parsedConfig.QueueList)-1] {
for _, q2 := range parsedConfig.QueueList[i+1:] {
if reflect.DeepEqual(q1, q2) {
return &ErrDuplicateQueueConfiguration{q1}
}
}
}
}
@ -278,10 +277,6 @@ func ParseConfig(reader io.Reader, region string, targetList *TargetList) (*Conf
return nil, err
}
if len(config.QueueList) == 0 {
return nil, errors.New("missing queue configuration(s)")
}
if err := config.Validate(region, targetList); err != nil {
return nil, err
}

@ -494,6 +494,9 @@ func TestConfigUnmarshalXML(t *testing.T) {
</TopicConfiguration>
</NotificationConfiguration>
`)
dataCase5 := []byte(`<NotificationConfiguration></NotificationConfiguration>`)
testCases := []struct {
data []byte
expectErr bool
@ -502,6 +505,8 @@ func TestConfigUnmarshalXML(t *testing.T) {
{dataCase2, false},
{dataCase3, false},
{dataCase4, true},
// make sure we don't fail when queue is empty.
{dataCase5, false},
}
for i, testCase := range testCases {

Loading…
Cancel
Save