fix(securitycenter) issue related to cleanup logic in testclass of ET…#9973
Conversation
ghost
left a comment
There was a problem hiding this comment.
Hi @lovenishs04 and reviewers,
I'm currently reviewing this pull request and will provide feedback shortly. In the meantime, here's a summary to help everyone quickly understand the changes:
This pull request addresses issue #9967 by improving the cleanup logic in the test class for the Event Threat Detection Custom Module. The primary changes are focused on ensuring that test-created custom modules are reliably deleted after test execution.
Here's a breakdown of the changes:
- Improved Cleanup: The
cleanUp()method inEventThreatDetectionCustomModuleTest.javahas been refactored. Instead of iterating through all custom modules and attempting to delete those matching a specific prefix (lines 74-105 in the original code), it now directly deletes only the custom modules created during the current test run. This is achieved by maintaining a list (createdCustomModuleIds) of the IDs of the created modules (added on lines 55, 115, 136, 150, 165, 179, 192, and 209). This targeted approach is more efficient and less prone to errors. - Added
createdCustomModuleIdsList: A newList<String> createdCustomModuleIdswas added to track the IDs of custom modules created during test execution (line 55). - Updated Test Methods: Several test methods (
testCreateEventThreatDetectionCustomModule,testListEventThreatDetectionCustomModules,testGetEventThreatDetectionCustomModule,testUpdateEventThreatDetectionCustomModule,testGetEffectiveEventThreatDetectionCustomModule,testListEffectiveEventThreatDetectionCustomModules, andtestListDescendantEventThreatDetectionCustomModules) were updated to add the newly created custom module IDs to thecreatedCustomModuleIdslist (lines 115, 136, 150, 165, 179, 192, and 209). - Removed Redundant Code: The
cleanupExistingCustomModulesmethod (lines 79-105) was removed as it's now redundant due to the improved cleanup logic. - Import Changes: Several unnecessary imports were removed from
EventThreatDetectionCustomModuleTest.java(lines 27-28).
I'll provide a more detailed review shortly.
Meanwhile, here's a little haiku to brighten your day:
Tests run, clean and swift,
Modules deleted, code is pure,
Peace reigns in the code.
ghost
left a comment
There was a problem hiding this comment.
This pull request improves the cleanup logic in the EventThreatDetectionCustomModuleTest by storing the IDs of created custom modules and deleting them explicitly in the cleanUp method. This is a good improvement over the previous approach, which relied on filtering by display name prefix, as it avoids potential issues with name collisions and ensures all test-created resources are properly cleaned up. The implementation is generally well-done, but there are a few minor suggestions for improvement.
minherz
left a comment
There was a problem hiding this comment.
lgtm. thank you for helping to reduce technical debt.
…D custom module
Description
Fixes #9967 Issue related to cleanup logic in testclass of Event Threat Detection Custom Module
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
pom.xmlparent set to latestshared-configurationmvn clean verifyrequiredmvn -P lint checkstyle:checkrequiredmvn -P lint clean compile pmd:cpd-check spotbugs:checkadvisory only