Skip to content

Commit 0b130cc

Browse files
committed
test: add unit tests for sanitizeClusterAdmins
Signed-off-by: Hyeonki Hong <[email protected]>
1 parent e1ef0d1 commit 0b130cc

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package kfam
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestSanitizeClusterAdmins(t *testing.T) {
9+
tests := []struct {
10+
name string
11+
in []string
12+
out []string
13+
}{
14+
{
15+
name: "empty slice",
16+
in: []string{},
17+
out: nil,
18+
},
19+
{
20+
name: "nil slice",
21+
in: nil,
22+
out: nil,
23+
},
24+
{
25+
name: "empty strings",
26+
in: []string{"", ""},
27+
out: nil,
28+
},
29+
{
30+
name: "whitespace only strings",
31+
in: []string{" ", " "},
32+
out: nil,
33+
},
34+
{
35+
name: "valid admins",
36+
37+
38+
},
39+
{
40+
name: "admins with leading spaces",
41+
in: []string{" [email protected]", " [email protected]"},
42+
43+
},
44+
{
45+
name: "admins with trailing spaces",
46+
in: []string{"[email protected] ", "[email protected] "},
47+
48+
},
49+
{
50+
name: "admins with leading and trailing spaces",
51+
in: []string{" [email protected] ", " [email protected] "},
52+
53+
},
54+
{
55+
name: "mixed empty, whitespace, and admins",
56+
in: []string{"", "[email protected]", " ", "[email protected] "},
57+
58+
},
59+
}
60+
61+
for _, tt := range tests {
62+
t.Run(tt.name, func(t *testing.T) {
63+
sanitized := sanitizeClusterAdmins(tt.in)
64+
if !reflect.DeepEqual(sanitized, tt.out) {
65+
t.Errorf("output: %v, expected: %v", sanitized, tt.out)
66+
}
67+
})
68+
}
69+
}

0 commit comments

Comments
 (0)