Commit e9926db
Expand unit test coverage for the cache layer and realization polling (#2316)
* Expand unit test coverage for low-coverage resources and data sources
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>
* Expand unit test coverage for the cache layer and realization polling
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>
---------
Co-authored-by: Kobi Samoray <kobis@Kobis-MacBook-Air.local>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>1 parent 8efb254 commit e9926db
3 files changed
Lines changed: 778 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
14 | | - | |
| 20 | + | |
15 | 21 | | |
16 | 22 | | |
17 | 23 | | |
| |||
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
30 | | - | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| |||
101 | 107 | | |
102 | 108 | | |
103 | 109 | | |
104 | | - | |
| 110 | + | |
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
| |||
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
142 | | - | |
| 148 | + | |
143 | 149 | | |
144 | 150 | | |
145 | 151 | | |
| |||
218 | 224 | | |
219 | 225 | | |
220 | 226 | | |
221 | | - | |
| 227 | + | |
222 | 228 | | |
223 | 229 | | |
224 | 230 | | |
| |||
286 | 292 | | |
287 | 293 | | |
288 | 294 | | |
289 | | - | |
| 295 | + | |
290 | 296 | | |
291 | 297 | | |
292 | 298 | | |
| |||
391 | 397 | | |
392 | 398 | | |
393 | 399 | | |
394 | | - | |
| 400 | + | |
395 | 401 | | |
396 | 402 | | |
397 | 403 | | |
| |||
414 | 420 | | |
415 | 421 | | |
416 | 422 | | |
417 | | - | |
| 423 | + | |
418 | 424 | | |
419 | 425 | | |
420 | 426 | | |
| |||
433 | 439 | | |
434 | 440 | | |
435 | 441 | | |
436 | | - | |
| 442 | + | |
437 | 443 | | |
438 | 444 | | |
439 | 445 | | |
| |||
456 | 462 | | |
457 | 463 | | |
458 | 464 | | |
459 | | - | |
| 465 | + | |
460 | 466 | | |
461 | 467 | | |
462 | 468 | | |
| |||
484 | 490 | | |
485 | 491 | | |
486 | 492 | | |
487 | | - | |
| 493 | + | |
488 | 494 | | |
489 | 495 | | |
490 | 496 | | |
| |||
494 | 500 | | |
495 | 501 | | |
496 | 502 | | |
497 | | - | |
| 503 | + | |
498 | 504 | | |
499 | 505 | | |
500 | 506 | | |
| |||
532 | 538 | | |
533 | 539 | | |
534 | 540 | | |
535 | | - | |
| 541 | + | |
536 | 542 | | |
537 | 543 | | |
538 | 544 | | |
| |||
568 | 574 | | |
569 | 575 | | |
570 | 576 | | |
571 | | - | |
| 577 | + | |
572 | 578 | | |
573 | 579 | | |
574 | 580 | | |
| |||
633 | 639 | | |
634 | 640 | | |
635 | 641 | | |
636 | | - | |
| 642 | + | |
637 | 643 | | |
638 | 644 | | |
639 | 645 | | |
| |||
0 commit comments