Skip to content

Add unit tests for the gpuop-cfg config validators - #2908

Open
abrarshivani wants to merge 1 commit into
NVIDIA:mainfrom
abrarshivani:unit-test-gpuop-cfg-validate
Open

abrarshivani wants to merge 1 commit into
NVIDIA:mainfrom
abrarshivani:unit-test-gpuop-cfg-validate

Conversation

@abrarshivani

Copy link
Copy Markdown
Contributor

Closes the remaining coverage gaps in cmd/gpuop-cfg/validate. Tests only — no production changes.

Coverage

Package Before After
validate 100% 100%
validate/clusterpolicy 26.7% 100%
validate/csv 55.4% 100%

cmd/gpuop-cfg stays at 0%: main ends in log.Exit, so its error path can't be covered in-process.

What's now covered

  • the operand walk in clusterpolicy.validateImages, which had never returned nil in a test
  • the related-image, deployment and env-var branches in csv.validateImages
  • both ManifestGet outcomes in validateImage
  • the CLI Before/Action closures, validateFlags and run, none previously invoked

Approach

  • validateImage builds its registry client inline, so the tests drive it through regclient's ocidir scheme against an OCI layout in t.TempDir() — hermetic, no network
  • the registry transport itself stays untested: HTTP, TLS, auth and retry are a different regclient backend, so read the numbers above as covering the validator's control flow only
  • each operand resolves at its own tag, so an error naming a tag names the operand that produced it — dropping an operand's block, duplicating another over it, or reading the wrong spec field each fail their own case

Pre-existing issues these tests ran into

Not fixed here, since this is tests-only. Flagging them rather than losing them:

  • empty CSV input panicscsv.validateImages indexes DeploymentSpecs[0]/Containers[0] unguarded, so gpuop-cfg validate csv on empty stdin dies with a stack trace instead of an error
  • digest references are corrupted — the driver and GDS paths get -ubuntu22.04 appended unconditionally, so a digest-pinned image becomes an invalid reference and can never validate
  • 9 of 20 image-bearing components are never validated — CCManager, DriverManager, GDRCopy, InitContainer, KataDevicePlugin, KataManager, NodeStatusExporter, Validator, VGPUManager
  • errors are wrapped with %v, not %w, so causes are flattened and assertions have to match on message text

Note for whoever fixes the digest issue: TestValidateImages_DriverImageOSTagAppended and its GDS counterpart assert the suffix is appended. They pin current behaviour and will need updating — they aren't an endorsement of it.

Happy to split any of the above into separate issues or PRs if useful.

Cover the remaining gaps in cmd/gpuop-cfg/validate: the operand walk in
clusterpolicy.validateImages, the deployment and env-var branches in
csv.validateImages, both ManifestGet outcomes in validateImage, and the
CLI Before/Action closures that were previously never invoked.

The registry client is constructed inline with no injection seam, so the
tests drive it through regclient's ocidir scheme against an OCI layout
written into t.TempDir(). That exercises the validator's own control flow
without a socket. The registry transport itself stays untested.

Each of the eleven operands resolves at its own tag, so an error naming a
tag names the operand whose field produced it. Dropping an operand's block,
duplicating another over it, or reading the wrong spec field all fail the
corresponding case.

clusterpolicy 26.7% -> 100%, csv 55.4% -> 100%.

Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Enterprise

Run ID: c04f7295-6e11-429f-b7c4-d475ddc714cb

📥 Commits

Reviewing files that changed from the base of the PR and between 8fe3fd6 and 71b4ae1.

📒 Files selected for processing (4)
  • cmd/gpuop-cfg/validate/clusterpolicy/clusterpolicy_test.go
  • cmd/gpuop-cfg/validate/clusterpolicy/images_test.go
  • cmd/gpuop-cfg/validate/csv/csv_test.go
  • cmd/gpuop-cfg/validate/csv/images_test.go

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

Expanded cluster policy and CSV validation tests. The tests cover malformed inputs, missing image configuration, OCI image resolution, operand validation, image tags, environment variables, optional GDS configuration, cancelled contexts, and missing ClusterPolicy data. Command tests write temporary inputs and run NewCommand.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 71b4a

This change only expands automated test coverage for existing validation logic and does not modify any production behavior, so it carries no direct risk to runtime behavior, data integrity, or security. Repository inspection did not surface any defects in the new tests themselves, so the change appears safe to merge pending normal CI verification.


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

@abrarshivani abrarshivani self-assigned this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant