Add unit tests for internal/state#2658
Draft
abrarshivani wants to merge 1 commit into
Draft
Conversation
abrarshivani
force-pushed
the
unit-test-state
branch
4 times, most recently
from
July 22, 2026 04:39
d763877 to
6d26bb8
Compare
Raise internal/state statement coverage from 37.8% to 97.2% with tests only. Cover info_source (100%), manager SyncState/GetWatchSources/newStates error paths, state_skel create/update/merge/getSyncState/isDaemonSetReady, driver Sync/getManifestObjects/handleDefaultImagesInObjects/cleanupStaleDriverDaemonsets, the GDS/GDRCopy/runtime spec helpers, driver spec/name/volume-config helpers, and nodepool selection, using the controller-runtime fake client with interceptors for injected errors and a fake manager where needed. The ~2.8% that remains is the reachable ceiling: each uncovered statement is either dead code (the getOSTag error branch that never fires; the SUSE /lib/modules block gated by contradictory UsePrecompiledDrivers conditions), a success return that loads the hardcoded on-disk path /opt/gpu-operator/manifests/state-driver, a live-informer predicate closure in GetWatchSources, or a provably-impossible SetNestedField error. Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
abrarshivani
force-pushed
the
unit-test-state
branch
from
July 23, 2026 19:38
6d26bb8 to
dbc251d
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
Raises
internal/statestatement coverage from 37.8% to 97.2%. Tests only — no production source changed. Tests use the controller-runtime fake client withinterceptor.Funcsto inject Get/List/Create/Update errors, a fake manager, the real manifest renderer, and computed DaemonSet hashes — exercising real success and error paths rather than tautologies.Now at 100%:
info_source.goin full, andNewStateDriver,Sync,cleanupStaleDriverDaemonsets,getDaemonsetFromObjects,getObjectOfKind,getDriverName,getDriverSpec,createConfigMapVolumeMounts,buildDriverInstallConfig,renderManifestObjects,getGDSSpec/getGDRCopySpec/getRuntimeSpec,createOrUpdateObjs,isDaemonSetReady,newStates, and thestateManagermethods.The remaining ~2.8% is the reachable ceiling
Every remaining uncovered statement is genuinely not exercisable by a unit test, verified against the source:
GetWatchSources— the uncovered block is an inlinepredicate.NewTypedPredicateFuncsclosure only invoked by a live controller-runtime informer on a DaemonSet watch event; the outer construction is covered via a fake manager.NewManager/newNVIDIADriverStatessuccess returns — require loading the hardcoded on-disk path/opt/gpu-operator/manifests/state-driver(a string literal, not an overridable var). All error paths are covered.getManifestObjects/handleDefaultImagesInObjects— in-loop error branches unreachable with a validNVIDIADriverspec (the spec is always populated, so templates render and always yield a DaemonSet); therenderManifestObjectserror itself is covered directly.mergeServiceAccount— twoSetNestedFieldwritebacks that cannot error (single top-level field on a map, value sourced from a validNestedSlice).Two genuine dead-code findings (not just coverage gaps)
While maximizing coverage, two blocks turned out to be unreachable due to source-level issues, worth flagging:
driver_volumes.go(~L224-243) — the SUSE/lib/modulesmount for precompiled drivers is guarded byif cr.Spec.UsePrecompiledDrivers() && ...but nested inside the enclosingif !cr.Spec.UsePrecompiledDrivers()block, a logical contradiction. This code can never execute; it looks like a real bug (precompiled-driver SUSE nodes never get/lib/modulesmounted).nodepool.go(~L102-104) — the error branch forgetOSTag, butgetOSTagunconditionally returns a nil error, so it is dead.These are left as-is in this tests-only PR; happy to address them separately if desired.
Checklist
make lint)make validate-generated-assets)make validate-modules)Testing