refactor: separate test-only scalers from production code#7372
refactor: separate test-only scalers from production code#7372dshmatov wants to merge 3 commits intokedacore:mainfrom
Conversation
Remove external-mock scaler from production buildScaler switch and implement a test scaler registry pattern instead. Previously, the external-mock scaler (used only for testing) was defined in the production buildScaler() switch statement, mixing test and production code. This resolves the TODO comment at line 182. Changes: - Remove external-mock case and TODO from buildScaler() - Add RegisterTestScalerBuilder() function for test-only scalers - Register external-mock in BeforeSuite via the registry pattern - Add unit tests to verify registry functionality Signed-off-by: Dmitriy Shmatov <dmitry.shmatov@wiliot.com> Signed-off-by: Dmitriy Shmatov <shmatov.dmitriy@gmail.com>
|
Thank you for your contribution! 🙏 Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected. While you are waiting, make sure to:
Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient. Learn more about our contribution guide. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
JorTurFer
left a comment
There was a problem hiding this comment.
Interesting approach! I'm thinking if we should register all the scaler builders as a map and just invoke them when needed. a map should be almost performant as a switch and it can remove all the testing code from the prod code registering the prod ones here and the extra one in the test file. WDYT @kedacore/keda-core-maintainers
@kedacore/keda-core-contributors
|
@JorTurFer yeah, good idea to replace this huge switch block! I can try to implement if everyone good with this approach |
Implement full registry pattern as suggested in PR feedback: - Replace 150-line switch statement with map-based registry - Register all production scalers in init() function - Unify test and production scaler registration Benefits: - Complete separation of test and production code - Eliminates large switch statement from buildScaler() - More extensible and maintainable architecture All existing tests pass with no functional changes. Signed-off-by: Dmitriy Shmatov <shmatov.dmitriy@gmail.com>
ca54bdc to
003d49a
Compare
Implement full registry pattern as suggested in PR feedback: - Replace 150-line switch statement with map-based registry - Register all production scalers in init() function - Unify test and production scaler registration Changes: - Created scalers_registry.go with init-based registration - Updated buildScaler() to use map lookup - Updated schema generator to parse registry format - Updated sort_scalers.sh to check registry file - Updated Makefile to point to registry file - Fixed unused parameter linter warnings Benefits: - Complete separation of test and production code - Eliminates large switch statement - More extensible and maintainable architecture Signed-off-by: Dmitriy Shmatov <shmatov.dmitriy@gmail.com>
|
I've implemented the full registry pattern - replaced the entire switch statement with map-based registration. All production scalers now register via init(), test scalers use the same RegisterScalerBuilder() API, and buildScaler() is now just a simple map lookup. |
Remove external-mock scaler from production buildScaler switch and implement a test scaler registry pattern instead.
Previously, the external-mock scaler (used only for testing) was defined in the production buildScaler() switch statement, mixing test and production code. This resolves the TODO comment at line 182.
Changes:
Checklist
make generate-scalers-schemahas been run to update any outdated generated files.Fixes #
Relates to #