-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s_test.go
36 lines (32 loc) · 1.04 KB
/
k8s_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package xo
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNormalizeAsRFC1123Name(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"Underscore to hyphen", "before_after", "before-after"},
{"Dots to hyphens", "1.1.1", "1-1-1"},
{"Trim hyphens", "-middle-", "middle"},
{"Special chars", "_@invalid.com", "invalid-com"},
{"Special chars at end", "invalid.com@.", "invalid-com"},
{"Multiple special chars", "_@invalid.com@.", "invalid-com"},
{"Only dots", "...", ""},
{"Non-ASCII chars", "中文中文", ""},
{"Mixed ASCII and non-ASCII", "中文abcd中文", "abcd"},
{"Max length 255", strings.Repeat("a", 255), strings.Repeat("a", 255)},
{"Over max length 256", strings.Repeat("a", 256), strings.Repeat("a", 256)},
{"Over max length 257", strings.Repeat("a", 257), strings.Repeat("a", 256)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := NormalizeAsRFC1123Name(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}