diff --git a/pkg/configmap/configmap_writer.go b/pkg/configmap/configmap_writer.go index 1ee4ff917..11846fad5 100644 --- a/pkg/configmap/configmap_writer.go +++ b/pkg/configmap/configmap_writer.go @@ -67,7 +67,7 @@ func NewConfigMapLoaderWithClient(configMapName, namespace, manifestsDir string, } func TranslateInvalidChars(input string) string { - validConfigMapKey := unallowedKeyChars.ReplaceAllString(input, "~") + validConfigMapKey := unallowedKeyChars.ReplaceAllString(input, "-") return validConfigMapKey } diff --git a/pkg/configmap/configmap_writer_test.go b/pkg/configmap/configmap_writer_test.go new file mode 100644 index 000000000..d91a3b333 --- /dev/null +++ b/pkg/configmap/configmap_writer_test.go @@ -0,0 +1,41 @@ +package configmap + +import ( + "testing" +) + +func TestTranslateInvalidChars(t *testing.T) { + t.Parallel() + + tt := []struct { + name string + input string + expectedOutput string + }{ + { + name: "identity when there're no invalid characters", + input: "foo-bar.yaml", + expectedOutput: "foo-bar.yaml", + }, + { + name: "input having invalid character", + input: "foo:bar.yaml", + expectedOutput: "foo-bar.yaml", + }, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + got := TranslateInvalidChars(tc.input) + if tc.expectedOutput != got { + t.Errorf("expected %s, got %s", tc.expectedOutput, got) + } + + if unallowedKeyChars.MatchString(got) { + t.Errorf("translated output %q contains invalid characters", got) + } + }) + } +}