Skip to content

test(graphql): Add mocked tests for ImageComponent resolver - #21542

Merged
rhybrillou merged 4 commits into
masterfrom
master-yann/graphql/image_component_tests
Jul 8, 2026
Merged

rhybrillou merged 4 commits into
masterfrom
master-yann/graphql/image_component_tests

Conversation

@rhybrillou

@rhybrillou rhybrillou commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests

How I validated my change

Test-only -> CI run

@openshift-ci

openshift-ci Bot commented Jul 3, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Expanded coverage for image component vulnerability GraphQL queries.
    • Verified filtering by CVE and fixable status, including combined filters.
    • Confirmed optional query inputs can be omitted and still return valid results.
    • Added validation for expected vulnerability details and proper error handling for invalid component IDs.

Walkthrough

Adds 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.

Changes

Image Component Vulnerability GraphQL Tests

Layer / File(s) Summary
Test fixtures and query constants
central/graphql/resolvers/image_components_mocked_test.go
Defines GraphQL query strings and test comments for the image component vulnerability scenarios.
Core GraphQL execution tests
central/graphql/resolvers/image_components_mocked_test.go
Adds standalone and suite-based tests covering fixable-CVE queries, filter combinations, and invalid component IDs.
Mock setup, validation, and response types
central/graphql/resolvers/image_components_mocked_test.go
Adds gomock setup, GraphQL response validation helpers, and local response/mock structs used by the tests.

Estimated code review effort: 2 (Simple) | ~15 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: mocked GraphQL tests for the ImageComponent resolver.
Description check ✅ Passed The description follows the template and covers the change, docs, testing, and validation, with only minor incomplete checklist items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch master-yann/graphql/image_component_tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
central/graphql/resolvers/image_components_mocked_test.go (1)

210-292: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant repeated mock setup across subtests.

setupImageComponentCVEMocks is invoked in every t.Run subtest (lines 212, 229, 246, 262), re-registering identical AnyTimes() expectations on the same controller each time. Functionally harmless but adds unnecessary boilerplate; consider calling once in SetupTest/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

📥 Commits

Reviewing files that changed from the base of the PR and between 58ce645 and 3c9dd40.

📒 Files selected for processing (1)
  • central/graphql/resolvers/image_components_mocked_test.go

@codecov

codecov Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.33%. Comparing base (3847494) to head (1eb8400).
⚠️ Report is 13 commits behind head on master.

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     
Flag Coverage Δ
go-unit-tests 50.33% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Build Images Ready

Images are ready for commit c1fd65e. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.12.x-410-gc1fd65eb66

@vikin91 vikin91 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread central/graphql/resolvers/image_components_mocked_test.go Outdated
Comment thread central/graphql/resolvers/image_components_mocked_test.go Outdated
Comment thread central/graphql/resolvers/image_components_mocked_test.go Outdated
Comment thread central/graphql/resolvers/image_components_mocked_test.go Outdated
@rhybrillou
rhybrillou force-pushed the master-yann/graphql/image_component_tests branch from 3c9dd40 to 475c4c2 Compare July 6, 2026 12:51

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 475c4c2 and 1eb8400.

📒 Files selected for processing (1)
  • central/graphql/resolvers/image_components_mocked_test.go

Comment thread central/graphql/resolvers/image_components_mocked_test.go
@rhybrillou

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@rhybrillou

Copy link
Copy Markdown
Contributor Author

/retest

@rhybrillou
rhybrillou merged commit c1fd65e into master Jul 8, 2026
117 of 121 checks passed
@rhybrillou
rhybrillou deleted the master-yann/graphql/image_component_tests branch July 8, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants