Skip to content

Add unit tests for cmd/gpuop-cfg config validators#2660

Draft
abrarshivani wants to merge 1 commit into
NVIDIA:mainfrom
abrarshivani:unit-test-cmd-validate
Draft

Add unit tests for cmd/gpuop-cfg config validators#2660
abrarshivani wants to merge 1 commit into
NVIDIA:mainfrom
abrarshivani:unit-test-cmd-validate

Conversation

@abrarshivani

Copy link
Copy Markdown
Contributor

Description

Adds hermetic unit tests for the cmd/gpuop-cfg/validate subtree (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/empty alm-examples annotation → unmarshal error; empty list → "no example clusterpolicy found"; first item Kind != ClusterPolicy → "invalid example clusterpolicy".
  • validateImage / validateImages (csv and clusterpolicy) — error paths only: an invalid image reference fails at ref.New before any registry call; an empty/zero ClusterPolicySpec fails at ImagePath ("failed to construct the image path"). The RelatedImages loop is exercised first so no nil-index panic and no network.
  • NewCommand constructors (validate, csv, clusterpolicy) — 100%: command name, usage, wired subcommands and the input flag.

Deliberately not covered (and why)

  • Happy paths of validateImage/validateImages — they call regclient.ManifestGet against a real container registry, which is not hermetic.
  • run / validateFlags / load / getContents and the CLI Before/Action closures — 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

  • No secrets, sensitive information, or unrelated changes
  • Lint checks passing (make lint)
  • Generated assets in-sync (make validate-generated-assets)
  • Go mod artifacts in-sync (make validate-modules)
  • Test cases are added for new code paths

Testing

go test ./cmd/gpuop-cfg/validate/... -covermode=count   # validateALMExample & NewCommands: 100%
golangci-lint run ./cmd/gpuop-cfg/validate/...           # 0 issues (GOOS=linux)

@copy-pr-bot

copy-pr-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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
abrarshivani force-pushed the unit-test-cmd-validate branch from 884cf22 to 1a54638 Compare July 23, 2026 19:38
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