From c726145baf121ed4cccef5d4ddf622890e56bf4f Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 20 Mar 2018 12:02:56 -0700 Subject: [PATCH] Fix regression in removing notification (#5673) fixes a regression introduced in 0e4431725cd85236d3d18643f8fc2506c7d88c66 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. --- pkg/event/config.go | 19 +++++++------------ pkg/event/config_test.go | 5 +++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/event/config.go b/pkg/event/config.go index b10a45d2b..5f5e6fea9 100644 --- a/pkg/event/config.go +++ b/pkg/event/config.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 } diff --git a/pkg/event/config_test.go b/pkg/event/config_test.go index 72b9e2436..52d84a08e 100644 --- a/pkg/event/config_test.go +++ b/pkg/event/config_test.go @@ -494,6 +494,9 @@ func TestConfigUnmarshalXML(t *testing.T) { `) + + dataCase5 := []byte(``) + 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 {