Skip to content

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

Open
rhybrillou wants to merge 3 commits into
masterfrom
master-yann/graphql/image_component_tests
Open

test(graphql): Add mocked tests for ImageComponent resolver#21542
rhybrillou wants to merge 3 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: d6976a65-81df-4ab7-9f45-343bab5d138f

📥 Commits

Reviewing files that changed from the base of the PR and between 3c9dd40 and 475c4c2.

📒 Files selected for processing (1)
  • central/graphql/resolvers/image_components_mocked_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • central/graphql/resolvers/image_components_mocked_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Expanded coverage for image component vulnerability queries.
    • Verified filtering by CVE and fixable status, plus handling of invalid component IDs.
    • Confirmed optional query inputs can be omitted while still returning valid results.

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 mocked fixture data for image components and CVEs.
Mock setup and response validation helpers
central/graphql/resolvers/image_components_mocked_test.go
Adds gomock setup, mock expectation helpers, GraphQL response validation helpers, and local view/DTO types.
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.
Variable typing test
central/graphql/resolvers/image_components_mocked_test.go
Adds a test verifying optional query variables can be omitted or nil.

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 describes the main change: adding mocked tests for the ImageComponent GraphQL resolver.
Description check ✅ Passed The PR description follows the template and covers the change, docs, testing notes, and CI reliance, with only minor checklist gaps.
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.32%. Comparing base (3847494) to head (475c4c2).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21542      +/-   ##
==========================================
- Coverage   50.36%   50.32%   -0.05%     
==========================================
  Files        2844     2844              
  Lines      218429   218429              
==========================================
- Hits       110004   109916      -88     
- Misses     100445   100515      +70     
- Partials     7980     7998      +18     
Flag Coverage Δ
go-unit-tests 50.32% <ø> (-0.05%) ⬇️

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 475c4c2. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.12.x-395-g475c4c2040

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


// region helper mock types

type flatComponentV2 struct {

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.

AI observation:

The file hand-rolls flatComponentV2 and flatCVEV2 structs to implement the imagecomponentflat.ComponentFlat and imagecveflat.CveFlat interfaces. But gomock-generated imageComponentFlatViewMocks.NewMockComponentFlat and imageCVEFlatViewMocks.NewMockCveFlat already exist and are used for exactly this purpose in the same package.

Comment on lines +295 to +296
// TestGraphQLVariableTypes validates that the GraphQL engine properly handles different variable types
func (s *ImageComponentVulnerabilitiesGraphQLTestSuite) TestGraphQLVariableTypes() {

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.

nit: this test name suggests that it validates that the GraphQL engine properly handles different variable types, but there are only two subtests with rather focused scope.

Okay to keep as it is if you have future plans for this test.

Comment on lines +499 to +512
type cveResponse struct {
CVE string `json:"cve"`
CVSS float64 `json:"cvss"`
Severity string `json:"severity"`
FixedByVersion string `json:"fixedByVersion"`
}

type imageComponentResponse struct {
Vulnerabilities []cveResponse `json:"vulnerabilities"`
}

type queryResponse struct {
Result imageComponentResponse `json:"result"`
}

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.

nit: we are in package resolvers and those structs will be also visible to the non-test code in the same package. Their names suggest nothing about them being test helpers. There are no conflicts currently, but using names that don't suggest test application may be a bit confusing to developers (actually no one now uses IDE to manually pick types from the auto-suggest lists, so this can be degraded to a super-nit comment).

assert.NotEmpty(t, response.Errors, "Query with invalid ID should produce errors")

if len(response.Errors) > 0 {
t.Logf("Expected error: %s", response.Errors[0].Error())

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.

Just log, no assertion here?

@rhybrillou rhybrillou force-pushed the master-yann/graphql/image_component_tests branch from 3c9dd40 to 475c4c2 Compare July 6, 2026 12:51
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