-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Bug on Events Configuration Equal function #1429
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
harshavardhana
requested changes
Dec 16, 2020
harshavardhana
requested changes
Dec 16, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the simplified diff
diff --git a/pkg/notification/notification.go b/pkg/notification/notification.go
index d150636..b17e6c5 100644
--- a/pkg/notification/notification.go
+++ b/pkg/notification/notification.go
@@ -180,30 +180,29 @@ func EqualFilterRuleList(a, b []FilterRule) bool {
// Equal returns whether this `Config` is equal to another defined by the passed parameters
func (t *Config) Equal(events []EventType, prefix, suffix string) bool {
- //Compare events
+ if t == nil {
+ return false
+ }
+
+ // Compare events
passEvents := EqualEventTypeList(t.Events, events)
- //Compare filters
- var newFilter []FilterRule
+ // Compare filters
+ var newFilterRules []FilterRule
if prefix != "" {
- newFilter = append(newFilter, FilterRule{Name: "prefix", Value: prefix})
+ newFilterRules = append(newFilterRules, FilterRule{Name: "prefix", Value: prefix})
}
if suffix != "" {
- newFilter = append(newFilter, FilterRule{Name: "suffix", Value: suffix})
+ newFilterRules = append(newFilterRules, FilterRule{Name: "suffix", Value: suffix})
}
- if len(newFilter) > 0 {
- // compare newFilter with Config.Filter
- if t.Filter != nil {
- passFilters := EqualFilterRuleList(t.Filter.S3Key.FilterRules, newFilter)
- return passEvents && passFilters
- }
- // if Config is nil, they are not equal
- return false
+ var currentFilterRules []FilterRule
+ if t.Filter != nil {
+ currentFilterRules = t.Filter.S3Key.FilterRules
}
- // if matches events and t.filter == nil
- return (t.Filter == nil) && passEvents
+ passFilters := EqualFilterRuleList(currentFilterRules, newFilterRules)
+ return passEvents && passFilters
}
If Config.Events was nil, it would cause an null pointer exception
f9492f5
to
0224f9a
Compare
@harshavardhana I've addressed it and added more tests for the function itself. |
harshavardhana
approved these changes
Dec 16, 2020
Alevsk
approved these changes
Dec 16, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This was referenced Mar 15, 2021
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If Config.Events was nil, it would cause an null pointer exception