Add unit tests for cmd/gpuop-cfg config validators#2660
Draft
abrarshivani wants to merge 1 commit into
Draft
Conversation
Add hermetic unit tests (no network/registry) for the gpuop-cfg validate subtree: - validateALMExample: full coverage (valid example, malformed JSON, missing/ empty annotation, empty list, wrong Kind). - validateImage/validateImages (csv and clusterpolicy): cover the pre-network error paths (invalid image reference, empty spec producing an image-path error). The registry happy paths are intentionally not unit-tested. - NewCommand constructors (validate, csv, clusterpolicy): full coverage of the command wiring (name, usage, subcommands, flags). Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
abrarshivani
force-pushed
the
unit-test-cmd-validate
branch
from
July 23, 2026 19:38
884cf22 to
1a54638
Compare
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 performs network, registry, or cluster access (verified by re-running the suite behind a dead HTTP(S) proxy).Covered
csv.validateALMExample— 100%: valid ClusterPolicy example → nil; malformed JSON → error; missing/emptyalm-examplesannotation → unmarshal error; empty list → "no example clusterpolicy found"; first itemKind != ClusterPolicy→ "invalid example clusterpolicy".validateImage/validateImages(csv and clusterpolicy) — error paths only: an invalid image reference fails atref.Newbefore any registry call; an empty/zeroClusterPolicySpecfails atImagePath("failed to construct the image path"). The RelatedImages loop is exercised first so no nil-index panic and no network.NewCommandconstructors (validate, csv, clusterpolicy) — 100%: command name, usage, wired subcommands and theinputflag.Deliberately not covered (and why)
validateImage/validateImages— they callregclient.ManifestGetagainst a real container registry, which is not hermetic.run/validateFlags/load/getContentsand the CLIBefore/Actionclosures — real file/STDIN reads and network validation; not unit-testable without I/O.As a result the subtree's package totals are modest by design (validate 100%, csv 38.5%, clusterpolicy 16.3%); the uncovered remainder is the network/file/entry-point code above.
Checklist
make lint)make validate-generated-assets)make validate-modules)Testing