Skip to content

Commit 9305580

Browse files
authored
Merge pull request #782 from sophotechlabs/test/flux-group-for
Add unit tests for FluxGroupFor
2 parents 6361a98 + 3207576 commit 9305580

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

api/v1/common_types_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,73 @@ import (
77
"testing"
88
)
99

10+
func TestFluxGroupFor(t *testing.T) {
11+
testCases := []struct {
12+
kind string
13+
expectedGroup string
14+
}{
15+
// Flux Operator kinds
16+
{FluxInstanceKind, GroupVersion.Group},
17+
{FluxReportKind, GroupVersion.Group},
18+
{ResourceSetKind, GroupVersion.Group},
19+
{ResourceSetInputProviderKind, GroupVersion.Group},
20+
// Source kinds
21+
{FluxGitRepositoryKind, FluxSourceGroup},
22+
{FluxOCIRepositoryKind, FluxSourceGroup},
23+
{FluxBucketKind, FluxSourceGroup},
24+
{FluxHelmChartKind, FluxSourceGroup},
25+
{FluxHelmRepositoryKind, FluxSourceGroup},
26+
{FluxExternalArtifactKind, FluxSourceGroup},
27+
// Notification kinds
28+
{FluxAlertKind, FluxNotificationGroup},
29+
{FluxAlertProviderKind, FluxNotificationGroup},
30+
{FluxReceiverKind, FluxNotificationGroup},
31+
// Image kinds
32+
{FluxImageRepositoryKind, FluxImageGroup},
33+
{FluxImagePolicyKind, FluxImageGroup},
34+
{FluxImageUpdateAutomationKind, FluxImageGroup},
35+
// Kustomize kind
36+
{FluxKustomizationKind, FluxKustomizeGroup},
37+
// Helm kind
38+
{FluxHelmReleaseKind, FluxHelmGroup},
39+
// Source extensions kind
40+
{FluxArtifactGeneratorKind, FluxSourceExtensionsGroup},
41+
}
42+
43+
for _, tc := range testCases {
44+
t.Run(tc.kind, func(t *testing.T) {
45+
gk, err := FluxGroupFor(tc.kind)
46+
if err != nil {
47+
t.Fatalf("unexpected error for kind %s: %v", tc.kind, err)
48+
}
49+
if gk.Group != tc.expectedGroup {
50+
t.Errorf("expected group %s, got %s", tc.expectedGroup, gk.Group)
51+
}
52+
if gk.Kind != tc.kind {
53+
t.Errorf("expected kind %s, got %s", tc.kind, gk.Kind)
54+
}
55+
})
56+
}
57+
}
58+
59+
func TestFluxGroupFor_UnknownKind(t *testing.T) {
60+
unknownKinds := []string{
61+
"Deployment",
62+
"Service",
63+
"UnknownKind",
64+
"",
65+
}
66+
67+
for _, kind := range unknownKinds {
68+
t.Run(kind, func(t *testing.T) {
69+
_, err := FluxGroupFor(kind)
70+
if err == nil {
71+
t.Error("expected error for unknown kind, got nil")
72+
}
73+
})
74+
}
75+
}
76+
1077
func TestFindFluxKindInfo_ExactMatch(t *testing.T) {
1178
testCases := []struct {
1279
input string

0 commit comments

Comments
 (0)