-
Notifications
You must be signed in to change notification settings - Fork 3
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: correct plugins config comparison #93
Conversation
This commit fixes a bug with the way Plugins config are compared: when unsorted nested arrays are present, `reflect.DeepEqual` considers the equal unsorted arrays as unequal, triggering the plugin update and showing misleading diffs. This commit is introducing a few helper functions to recursively sort arrays within the Kong Plugins configs.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #93 +/- ##
==========================================
+ Coverage 41.02% 41.16% +0.14%
==========================================
Files 74 74
Lines 10760 10795 +35
==========================================
+ Hits 4414 4444 +30
- Misses 5886 5890 +4
- Partials 460 461 +1 ☔ View full report in Codecov by Sentry. |
pkg/state/types.go
Outdated
// Helper function to sort a slice of interface{} | ||
func sortInterfaceSlice(slice []interface{}) []interface{} { | ||
// Convert []interface{} to []string for sorting | ||
strSlice := make([]string, len(slice)) | ||
for i, v := range slice { | ||
strSlice[i] = fmt.Sprintf("%v", v) | ||
} | ||
|
||
sort.Strings(strSlice) | ||
|
||
// Convert back to []interface{} | ||
sortedSlice := make([]interface{}, len(strSlice)) | ||
for i, v := range strSlice { | ||
sortedSlice[i] = v | ||
} | ||
|
||
return sortedSlice | ||
} |
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.
How about using a type that can be sorted and thus not allocating unnecessarily?
Something like this: d7c9b78
WDYT?
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.
Looks like a nice improvement!
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.
Pushed it directly to this PR: d7c9b78.
PTAL
This commit fixes a bug with the way Plugins config are compared: when unsorted nested arrays are present,
reflect.DeepEqual
considers the equal unsorted arrays as unequal, triggering the plugin update and showing misleading diffs.This commit is introducing a few helper functions to recursively sort arrays within the Kong Plugins configs.
Summary
SUMMARY_GOES_HERE
Full changelog
Issues resolved
Fix #XXX
Documentation
Testing