...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package k8s_test
16
17 import (
18 "testing"
19
20 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
21 )
22
23 func TestValueToDNSSubdomainName(t *testing.T) {
24 testCases := []struct {
25 Name string
26 Value string
27 ExpectedResult string
28 }{
29 {
30 Name: "empty string",
31 Value: "",
32 ExpectedResult: "a",
33 },
34 {
35 Name: "Strip non-alphanumeric",
36 Value: "this-name-contains-#chars;_that#shouldbe-replaced",
37 ExpectedResult: "this-name-contains--chars--that-shouldbe-replaced",
38 },
39 {
40 Name: "Periods and hyphens",
41 Value: "this.is-legal",
42 ExpectedResult: "this.is-legal",
43 },
44 {
45 Name: "Number",
46 Value: "0123456789",
47 ExpectedResult: "0123456789",
48 },
49 {
50 Name: "hyphen prefix",
51 Value: "-value",
52 ExpectedResult: "a-value",
53 },
54 {
55 Name: "hyphen prefix period suffix",
56 Value: "-value.",
57 ExpectedResult: "a-value.a",
58 },
59 }
60 for _, tc := range testCases {
61 t.Run(tc.Name, func(t *testing.T) {
62 result := k8s.ValueToDNSSubdomainName(tc.Value)
63 if result != tc.ExpectedResult {
64 t.Fatalf("result mismatch: got '%v', want '%v'", result, tc.ExpectedResult)
65 }
66 })
67 }
68 }
69
View as plain text