Skip to content

Commit 947dd21

Browse files
Kobi Samorayclaude
authored andcommitted
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> Claude-Session: https://claude.ai/code/session_01ESMNTML2d2NLax7MHUizHe
1 parent 602e067 commit 947dd21

3 files changed

Lines changed: 769 additions & 8 deletions

File tree

nsxt/cache_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//go:build unittest
2+
3+
// © Broadcom. All Rights Reserved.
4+
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
5+
// SPDX-License-Identifier: MPL-2.0
6+
17
package nsxt
28

39
import (
@@ -10,7 +16,7 @@ import (
1016
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
1117
)
1218

13-
func TestProviderManagedTagsSearchQuery(t *testing.T) {
19+
func TestUnitNsxt_providerManagedTagsSearchQuery(t *testing.T) {
1420
if got := providerManagedTagsSearchQuery(""); got != "" {
1521
t.Fatalf("empty runID: want empty, got %q", got)
1622
}
@@ -26,7 +32,7 @@ func TestProviderManagedTagsSearchQuery(t *testing.T) {
2632
}
2733
}
2834

29-
func TestBuildTagQuery(t *testing.T) {
35+
func TestUnitNsxt_buildTagQuery(t *testing.T) {
3036
tagSchema := map[string]*schema.Schema{
3137
"tag": {
3238
Type: schema.TypeSet,
@@ -100,7 +106,7 @@ func TestBuildTagQuery(t *testing.T) {
100106
})
101107
}
102108

103-
func TestAttachRulesByParentPathSecurityPolicy(t *testing.T) {
109+
func TestUnitNsxt_attachRulesByParentPathSecurityPolicy(t *testing.T) {
104110
policyPathA := "/infra/domains/default/security-policies/pol-a"
105111
policyPathB := "/infra/domains/default/security-policies/pol-b"
106112

@@ -138,7 +144,7 @@ func TestAttachRulesByParentPathSecurityPolicy(t *testing.T) {
138144
})
139145
}
140146

141-
func TestEnsureProviderManagedTagsWithPatchFunc(t *testing.T) {
147+
func TestUnitNsxt_ensureProviderManagedTagsWithPatchFunc(t *testing.T) {
142148
type testTagObj struct {
143149
Tags []model.Tag
144150
}
@@ -217,7 +223,7 @@ func int64Ptr(v int64) *int64 {
217223
return &v
218224
}
219225

220-
func TestGroupRulesByValidParentPath(t *testing.T) {
226+
func TestUnitNsxt_groupRulesByValidParentPath(t *testing.T) {
221227
pathA := "/policies/a"
222228
pathB := "/policies/b"
223229
valid := map[string]struct{}{pathA: {}, pathB: {}}
@@ -285,7 +291,7 @@ func attachRulesToSecurityPoliciesForTest(parents []model.SecurityPolicy, rules
285291
)
286292
}
287293

288-
func TestAttachRulesByParentPathGatewayPolicy(t *testing.T) {
294+
func TestUnitNsxt_attachRulesByParentPathGatewayPolicy(t *testing.T) {
289295
policyPathA := "/orgs/p/proj/vpcs/vpc/gateway-policies/pol-a"
290296
policyPathB := "/orgs/p/proj/vpcs/vpc/gateway-policies/pol-b"
291297

@@ -390,7 +396,7 @@ func TestAttachRulesByParentPathGatewayPolicy(t *testing.T) {
390396
})
391397
}
392398

393-
func TestErrCacheUseBackendDirect(t *testing.T) {
399+
func TestUnitNsxt_errCacheUseBackendDirect(t *testing.T) {
394400
if !errors.Is(errCacheUseBackendDirect, errCacheUseBackendDirect) {
395401
t.Fatal("errors.Is should match sentinel to itself")
396402
}
@@ -400,7 +406,7 @@ func TestErrCacheUseBackendDirect(t *testing.T) {
400406
}
401407
}
402408

403-
func TestReflectStringField(t *testing.T) {
409+
func TestUnitNsxt_reflectStringField(t *testing.T) {
404410
t.Run("returns-pointer-value", func(t *testing.T) {
405411
obj := &model.Group{DisplayName: strPtr("g1")}
406412
got := reflectStringField(obj, "DisplayName")

0 commit comments

Comments
 (0)