Skip to content

Comments

fix(securitycenter) issue related to cleanup logic in testclass of ET…#9973

Merged
lovenishs04 merged 1 commit intoGoogleCloudPlatform:mainfrom
lovenishs04:fix-scc-management-api-etd-modules-cleanup
Jan 15, 2025
Merged

fix(securitycenter) issue related to cleanup logic in testclass of ET…#9973
lovenishs04 merged 1 commit intoGoogleCloudPlatform:mainfrom
lovenishs04:fix-scc-management-api-etd-modules-cleanup

Conversation

@lovenishs04
Copy link
Contributor

…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

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@lovenishs04 lovenishs04 requested review from a team and yoshi-approver as code owners January 13, 2025 08:57
@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: securitycenter Issues related to the Security Command Center API. labels Jan 13, 2025
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in EventThreatDetectionCustomModuleTest.java has 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 createdCustomModuleIds List: A new List<String> createdCustomModuleIds was 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, and testListDescendantEventThreatDetectionCustomModules) were updated to add the newly created custom module IDs to the createdCustomModuleIds list (lines 115, 136, 150, 165, 179, 192, and 209).
  • Removed Redundant Code: The cleanupExistingCustomModules method (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.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lovenishs04 lovenishs04 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 13, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 13, 2025
Copy link
Contributor

@minherz minherz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. thank you for helping to reduce technical debt.

@lovenishs04 lovenishs04 merged commit 57fc720 into GoogleCloudPlatform:main Jan 15, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: securitycenter Issues related to the Security Command Center API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor the clean up logic implementation in security-command-center/snippets/src/test/java/management/api/EventThreatDetectionCustomModuleTest.java

4 participants