Repository navigation
test(graphql): Add mocked tests for ImageComponent resolver - #21542
Conversation
|
Skipping CI for Draft Pull Request. |
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a new Go test file for GraphQL image component vulnerability queries. It introduces shared fixtures and mock helpers, then exercises fixable-CVE resolution, filter handling, invalid-component errors, and optional variable behavior. ChangesImage Component Vulnerability GraphQL Tests
Estimated code review effort: 2 (Simple) | ~15 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
central/graphql/resolvers/image_components_mocked_test.go (1)
210-292: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRedundant repeated mock setup across subtests.
setupImageComponentCVEMocksis invoked in everyt.Runsubtest (lines 212, 229, 246, 262), re-registering identicalAnyTimes()expectations on the same controller each time. Functionally harmless but adds unnecessary boilerplate; consider calling once inSetupTest/before the subtests instead.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@central/graphql/resolvers/image_components_mocked_test.go` around lines 210 - 292, The `setupImageComponentCVEMocks` setup is being repeated in each `t.Run` subtest, which re-registers the same `AnyTimes()` expectations on the shared mock container. Move that common mock initialization out of the individual subtests in `image_components_mocked_test.go`—ideally into `SetupTest` or once before the subtests—so the `query without filters`, `query with vulnQuery filter`, `query with fixable filter`, and `query with combined filters` cases only focus on query-specific inputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@central/graphql/resolvers/image_components_mocked_test.go`:
- Around line 210-292: The `setupImageComponentCVEMocks` setup is being repeated
in each `t.Run` subtest, which re-registers the same `AnyTimes()` expectations
on the shared mock container. Move that common mock initialization out of the
individual subtests in `image_components_mocked_test.go`—ideally into
`SetupTest` or once before the subtests—so the `query without filters`, `query
with vulnQuery filter`, `query with fixable filter`, and `query with combined
filters` cases only focus on query-specific inputs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 43f51f17-5421-4bac-98d2-a0cdff8b8225
📒 Files selected for processing (1)
central/graphql/resolvers/image_components_mocked_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #21542 +/- ##
==========================================
- Coverage 50.36% 50.33% -0.03%
==========================================
Files 2844 2844
Lines 218429 218476 +47
==========================================
- Hits 110004 109964 -40
- Misses 100445 100510 +65
- Partials 7980 8002 +22
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 Build Images ReadyImages are ready for commit c1fd65e. To use with deploy scripts: export MAIN_IMAGE_TAG=4.12.x-410-gc1fd65eb66 |
vikin91
left a comment
There was a problem hiding this comment.
I am not a graphql expert, but gave it a shot anyway. If you need a deeper review, then I would suggest to involve an additional reviewer.
Solid addition of working test coverage. I have few observations in the comments, but none of them are blocking.
3c9dd40 to
475c4c2
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@central/graphql/resolvers/image_components_mocked_test.go`:
- Around line 286-288: The test setup in image_components_mocked_test.go uses
invalid new(...) calls that pass values instead of types, so fix the
initialization around the observed vulnerability fields by replacing the bad
pointers in the test block that defines now, moderateVuln, and observedState.
Use the existing symbols time.Now,
storage.VulnerabilitySeverity_MODERATE_VULNERABILITY_SEVERITY, and
storage.VulnerabilityState_OBSERVED by first assigning them to local values and
then taking their addresses where a pointer is required.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 578fe3d1-bc5a-4ac7-b8c3-85ac73c3a3de
📒 Files selected for processing (1)
central/graphql/resolvers/image_components_mocked_test.go
|
/retest |
1 similar comment
|
/retest |
Description
Multiple dependabot pull-requests to upgrade the github.com/graph-gophers/graphql-go failed after the dependency introduced a breaking behaviour change ( see graph-gophers/graphql-go#763 ).
This PR introduces a set of unit tests that helped with the investigation of the upgrade failures.
The pull request is part of a stack:
User-facing documentation
is updated ORupdate is not neededis created and is linked above ORis not neededTesting and quality
Automated testing
How I validated my change
Test-only -> CI run