-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
test: replace mock with memory cache and fix non-deterministic tests #8410
Conversation
This commit updates the local scanner tests to use a memory cache instead of mocking the applier. The changes include: - Removing mock applier files - Updating test cases to use `setupCache` function - Simplifying test setup and improving test readability - Adding package identifier details to test packages
This commit introduces sorting capabilities for various collections in the artifact details: - Added sort methods for Applications, Secrets, and LicenseFiles - Implemented a Sort() method for ArtifactDetail to consistently sort different collections - Updated types to support sorting based on specific criteria like type, file path, and package count
Modify CycloneDX JSON test data: - Remove license entry for pom.xml - Add empty license text fields for Java package licenses - Reorder license entries in the JSON structure
Change the wantApps variable type from []types.Application to types.Applications to align with recent sorting and collection updates
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.
@knqyf263 LGTM
left couple small comments.
pkg/scanner/local/scan_test.go
Outdated
python39min, | ||
{ | ||
FilePath: "usr/lib/python/site-packages/urllib3-3.2.1/METADATA", | ||
Packages: []ftypes.Package{urllib3Pkg}, |
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.
Previous test included python39min
:
trivy/pkg/scanner/local/scan_test.go
Line 316 in 3e503a0
python39min, |
Add this package here or remove this variable (because it is not used):
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.
it looks like this file doesn't have changes.
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.
It's sorted now.
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.
ah, i understood how the new sorting affected.
Sorry for disturbing you
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.
No problem. Thanks for your comment. I've removed unneeded fields.
1f71820
Remove empty license text fields for package licenses in CycloneDX JSON test data
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
Overview
This PR refactors scanner tests to use memory cache instead of mocks, which revealed the need for consistent sorting of artifact details.
Description
Scanner Test Refactoring
ApplyLayers
Artifact Details Sorting (to fix non-deterministic tests)
To address the non-deterministic test results discovered during the refactoring, added sorting capabilities:
The addition of sorting was necessary because the previous mock-based tests were masking the undefined ordering of collections in the actual implementation.
Checklist