Add unit tests for cmd/gpuop-cfg config validators - #2660
Merged
Merged
Conversation
abrarshivani
force-pushed
the
unit-test-cmd-validate
branch
from
July 23, 2026 19:38
884cf22 to
1a54638
Compare
abrarshivani
marked this pull request as ready for review
July 28, 2026 18:51
abrarshivani
requested review from
cdesiniotis,
karthikvetrivel,
rahulait,
rajathagasthya,
shivamerla and
tariq1890
as code owners
July 28, 2026 18:51
Contributor
|
Can you rebase this PR and squash the commit history? |
Cover the csv and clusterpolicy validators under cmd/gpuop-cfg/validate: alm-examples parsing (including apiVersion-ignored, empty/null list, and unmarshal error boundaries), image validation, options load/getContents (file and stdin), and the flag/subcommand wiring. Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
abrarshivani
force-pushed
the
unit-test-cmd-validate
branch
from
July 29, 2026 22:59
c37738e to
0f5ead4
Compare
Contributor
Author
|
@tariq1890 I have rebased and squashed the commits. Can you please take look? |
tariq1890
approved these changes
Jul 29, 2026
abrarshivani
enabled auto-merge
July 30, 2026 00:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds hermetic unit tests for the
cmd/gpuop-cfg/validatesubtree (previously 0% covered). Tests only — no production source changed. No test reaches registry access: every image case fails during image-path construction or reference parsing beforeManifestGet(control-flow, not just verified behind a dead proxy).Covered
csv.validateALMExample— 100%: first itemKind == ClusterPolicy→ nil; malformed JSON → "invalid character"; missing/empty/null/nil-annotation → unmarshal or "no example clusterpolicy found"; JSON object instead of array → "cannot unmarshal object"; empty list → "no example clusterpolicy found"; first itemKind != ClusterPolicy(including when a ClusterPolicy appears later) → "invalid example clusterpolicy". (Note: the validator only checkscpList[0].Kind; the multi-entry cases document that contract.)options.load/options.getContents(csv and clusterpolicy) — 100%: valid manifest, missing file, malformed YAML, empty file (viat.TempDir), and theinput == "-"stdin branch (via anos.Piperedirect). Local file/stdin I/O is deterministic and hermetic.validateImage/validateImages(csv and clusterpolicy) — error paths only: an invalid image reference fails atref.Newbefore any registry call; an empty/zero spec fails atImagePathbefore any registry access. Assertions userequire.ErrorContains.NewCommandconstructors (validate, csv, clusterpolicy) — 100%: command name/usage, subcommand presence (not an exact count), and theinputflag located by name with its type (*cli.StringFlag), names, usage, and default"-"asserted.Deliberately not covered (and why)
validateImage/validateImages— they construct aregclientinternally and callManifestGetagainst a real container registry, so they aren't hermetically unit-testable without a production refactor (injectable manifest getter). Tracked as follow-up.The subtree's package totals are modest by design (validate 100%, csv 55.4%, clusterpolicy 26.9%); the uncovered remainder is the registry/entry-point code above.
Follow-ups (production changes, out of scope for this tests-only PR)
csv.validateImagesagainst a CSV with noDeploymentSpecs/Containers(currently indexes[0]unchecked → possible panic on a malformed CSV).validateALMExample(nil)handling (currently dereferencescsv.Annotations).validateImage; wrap nested errors with%w.Checklist
make lint)make validate-generated-assets)make validate-modules)Testing