...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package krmtotf_test
16
17 import (
18 "testing"
19
20 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/krmtotf"
21 )
22
23 func TestKRMNameToTerraformID(t *testing.T) {
24 tests := []struct {
25 name string
26 krmName string
27 want string
28 }{
29 {
30 name: "only alphanumerics",
31 krmName: "badabingbadazoom128",
32 want: "badabingbadazoom128",
33 },
34 {
35 name: "dashes should become underscores",
36 krmName: "x-y-z",
37 want: "x_y_z",
38 },
39 {
40 name: "dots should become underscores",
41 krmName: "x.y.z",
42 want: "x_y_z",
43 },
44 {
45 name: "dashes and dots in same string",
46 krmName: "x.y-z",
47 want: "x_y_z",
48 },
49 }
50 for _, tc := range tests {
51 tc := tc
52 t.Run(tc.name, func(t *testing.T) {
53 t.Parallel()
54 got := krmtotf.KRMNameToTerraformID(tc.krmName)
55 if got != tc.want {
56 t.Errorf("KRMNameToTerraformId(%v) = %v, want: %v", tc.krmName, got, tc.want)
57 }
58 })
59 }
60 }
61
View as plain text