Skip to content

Expand unit test coverage for the cache layer and realization polling - #2316

Open
ksamoray wants to merge 2 commits into
vmware:masterfrom
ksamoray:ut-coverage3
Open

Expand unit test coverage for the cache layer and realization polling#2316
ksamoray wants to merge 2 commits into
vmware:masterfrom
ksamoray:ut-coverage3

Conversation

@ksamoray

@ksamoray ksamoray commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

cache_test.go's tests predated the unittest tag convention and were named
outside the TestMockNsxt/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.

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>
@ksamoray
ksamoray requested a review from a team September 6, 2026 06:55
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>

@yuanyouyao yuanyouyao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve / LGTM. This PR completes the unit test coverage suite for the caching layer with high precision and zero regressions.

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.

2 participants