forked from Azure/azure-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlabel_test.go
71 lines (63 loc) · 1.89 KB
/
label_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package names
import (
"testing"
)
//cspell:disable
func TestLabelName(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"Lowercase", "myproject", "myproject"},
{"Uppercase", "MYPROJECT", "myproject"},
{"MixedCase", "myProject", "my-project"},
{"MixedCaseEnd", "myProjecT", "my-project"},
{"TitleCase", "MyProject", "my-project"},
{"TitleCaseEnd", "MyProjecT", "my-project"},
{"WithDot", "my.project", "my-project"},
{"WithDotTitleCase", "My.Project", "my-project"},
{"WithHyphen", "my-project", "my-project"},
{"WithHyphenTitleCase", "My-Project", "my-project"},
{"StartWithNumber", "1myproject", "1myproject"},
{"EndWithNumber", "myproject2", "myproject2"},
{"MixedWithNumbers", "my2Project3", "my2-project3"},
{"SpecialCharacters", "my_project!@#", "my-project"},
{"EmptyString", "", ""},
{"DotOnly", ".", ""},
{"OnlySpecialCharacters", "@#$%^&*", ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := LabelName(tt.input)
if result != tt.expected {
t.Errorf("LabelName(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}
func TestLabelNameEdgeCases(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"SingleCharacter", "A", "a"},
{"TwoCharacters", "Ab", "ab"},
{"StartEndHyphens", "-abc-", "abc"},
{"LongString",
"ThisIsOneVeryLongStringThatExceedsTheSixtyThreeCharacterLimitForRFC1123LabelNames",
"this-is-one-very-long-string-that-exceeds-the-sixty-three-character-limit-for-rfc1123-label-names"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := LabelName(tt.input)
if result != tt.expected {
t.Errorf("LabelName(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}
//cspell:enable