Expand unit test coverage for the cache layer and realization polling - #2316
Open
ksamoray wants to merge 2 commits into
Open
Expand unit test coverage for the cache layer and realization polling#2316ksamoray wants to merge 2 commits into
ksamoray wants to merge 2 commits into
Conversation
Raises overall unit test coverage on ./nsxt/... from 68.8% to 73.8%, building on the prior "near-zero-coverage data sources" pass: - 8 resources whose existing mock tests only exercised error/guard paths now cover Create/Read/Update/Delete success paths too: cluster_security_config (20% -> ~97%), ldap_identity_source (20% -> ~97%), l7_access_profile (24% -> ~89%), idps_cluster_config (25% -> ~97%), segment_port_profile_bindings (33% -> ~86%), host_transport_node (36% -> ~88%), ip_pool_block_subnet (37% -> ~90%), ipsec_vpn_session (41% -> ~74%). Adds minimal package-level client-constructor seams (mirroring the existing cli*Client convention used throughout the provider) to cluster_security_config and idps_cluster_config so their SDK clients can be mocked; reuses existing seams elsewhere. - 9 near-identical LB monitor/application profile resources gain success-path tests via their already-shared mock helpers, raising each from ~46-50% to 84-100%. - 13 data sources that previously had no mock test at all now have one, nearly all reaching 100%: 8 trivial generic-search wrappers, plus provider_info, host_upgrade_group, edge_cluster, gateway_interface, and proxy_config (the last reusing an existing seam from its sibling resource file instead of constructing its SDK client inline). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
cache_test.go's tests predated the unittest tag convention and were named outside the TestMock*Nsxt*/TestUnitNsxt_* pattern that `make test-unit` (and CI) filters on via -run, so they never actually executed as part of the tracked unit test suite. Tag the file `//go:build unittest` and rename its tests to TestUnitNsxt_* so they're finally counted. Add nsxt/cache_unit_test.go covering the cache.go helpers that were still at 0%: query-string/query-key construction, the per-type/per-query cache buckets (hit, miss-and-populate, and post-write-bypass paths) including the composite gateway-policy/security-policy + rule merge, tag stripping and provider-managed-tag patching, and TryCacheRead/CacheAwareResourceRead/ cacheAwareDataSourceReadByID end to end using the existing cliQueryClient stub pattern from policy_search_unit_test.go. Also add coverage for nsxtPolicyWaitForRealizationStateConf (policy_utils.go), reusing the existing realization-info mock helper to exercise its Refresh closure (found, not-yet-realized, and error cases). Package coverage under `go test ./nsxt -tags=unittest -run='^(TestMock.*Nsxt.*|TestUnitNsxt_.*)' -coverpkg=./nsxt` moves from 74.0% to 74.8%, with cache.go itself going from mostly-0% to 75-100% coverage across nearly every function. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ksamoray
force-pushed
the
ut-coverage3
branch
from
September 6, 2026 07:14
947dd21 to
73f2d17
Compare
yuanyouyao
approved these changes
Sep 7, 2026
yuanyouyao
left a comment
Contributor
There was a problem hiding this comment.
Approve / LGTM. This PR completes the unit test coverage suite for the caching layer with high precision and zero regressions.
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.
cache_test.go's tests predated the unittest tag convention and were named
outside the TestMockNsxt/TestUnitNsxt_* pattern that
make test-unit(andCI) filters on via -run, so they never actually executed as part of the
tracked unit test suite. Tag the file
//go:build unittestand rename itstests to TestUnitNsxt_* so they're finally counted.
Add nsxt/cache_unit_test.go covering the cache.go helpers that were still at
0%: query-string/query-key construction, the per-type/per-query cache
buckets (hit, miss-and-populate, and post-write-bypass paths) including the
composite gateway-policy/security-policy + rule merge, tag stripping and
provider-managed-tag patching, and TryCacheRead/CacheAwareResourceRead/
cacheAwareDataSourceReadByID end to end using the existing cliQueryClient
stub pattern from policy_search_unit_test.go.
Also add coverage for nsxtPolicyWaitForRealizationStateConf (policy_utils.go),
reusing the existing realization-info mock helper to exercise its Refresh
closure (found, not-yet-realized, and error cases).
Package coverage under
go test ./nsxt -tags=unittest -run='^(TestMock.*Nsxt.*|TestUnitNsxt_.*)' -coverpkg=./nsxtmoves from 74.0% to 74.8%, with cache.go itself going from mostly-0% to
75-100% coverage across nearly every function.