Skip to content

Commit 35c9e28

Browse files
committed
Codecov test case fixing
Signed-off-by: Abhijeet Dey <[email protected]>
1 parent 5ad09e8 commit 35c9e28

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

utils/component/generator.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ func GroupToModel(group, fallbackName string) (modelName, displayName string) {
7575
}
7676
return group, strings.Join(parts, " ")
7777
}
78-
return fallbackName, manifests.FormatToReadableString(fallbackName)
78+
// Fallback: format and ensure leading character is capitalized for display
79+
display := manifests.FormatToReadableString(fallbackName)
80+
if display != "" {
81+
display = strings.ToUpper(display[:1]) + display[1:]
82+
}
83+
return fallbackName, display
7984
}
8085

8186
// ExtractGroupFromAPIVersion returns the API group from a k8s apiVersion string like "group/version".

utils/component/generator_test.go

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,39 @@ func TestGenerate(t *testing.T) {
156156
}
157157
}
158158

159-
func TestGroupToModel_WithGroup(t *testing.T) {
160-
name, display := GroupToModel("monitor.azure.com", "fallback")
161-
if name != "monitor.azure.com" {
162-
t.Fatalf("expected model name 'monitor.azure.com', got '%s'", name)
163-
}
164-
if display != "Monitor Azure Com" {
165-
t.Fatalf("expected display name 'Monitor Azure Com', got '%s'", display)
166-
}
167-
}
168-
169-
func TestGroupToModel_EmptyGroup(t *testing.T) {
170-
name, display := GroupToModel("", "fooBarBaz")
171-
if name != "fooBarBaz" {
172-
t.Fatalf("expected fallback model name 'fooBarBaz', got '%s'", name)
159+
func TestGroupToModel(t *testing.T) {
160+
cases := []struct {
161+
name string
162+
group string
163+
fallback string
164+
expectName string
165+
expectDisplay string
166+
}{
167+
{
168+
name: "with group",
169+
group: "monitor.azure.com",
170+
fallback: "ignored",
171+
expectName: "monitor.azure.com",
172+
expectDisplay: "Monitor Azure Com",
173+
},
174+
{
175+
name: "empty group uses fallback",
176+
group: "",
177+
fallback: "fooBarBaz",
178+
expectName: "fooBarBaz",
179+
expectDisplay: "Foo Bar Baz",
180+
},
173181
}
174-
if display != "Foo Bar Baz" {
175-
t.Fatalf("expected display name 'Foo Bar Baz', got '%s'", display)
182+
for _, tc := range cases {
183+
t.Run(tc.name, func(t *testing.T) {
184+
name, display := GroupToModel(tc.group, tc.fallback)
185+
if name != tc.expectName {
186+
t.Fatalf("expected model name '%s', got '%s'", tc.expectName, name)
187+
}
188+
if display != tc.expectDisplay {
189+
t.Fatalf("expected display name '%s', got '%s'", tc.expectDisplay, display)
190+
}
191+
})
176192
}
177193
}
178194

0 commit comments

Comments
 (0)