Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the "./" prefix before sanitizing the integration name. #309

Merged
merged 1 commit into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/util/kubernetes/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var disallowedChars = regexp.MustCompile(`[^a-z0-9-]`)

// SanitizeName sanitizes the given name to be compatible with k8s
func SanitizeName(name string) string {
name = strings.TrimPrefix(name, "./")
name = strings.Split(name, ".")[0]
name = path.Base(name)
name = strcase.KebabCase(name)
Expand Down
37 changes: 37 additions & 0 deletions pkg/util/kubernetes/sanitize_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package kubernetes

import (
"testing"
)

func TestSanitizeName(t *testing.T) {
cases := []map[string]string{
{"input": "./abc.java", "expect": "abc"},
{"input": "/path/to/abc.js", "expect": "abc"},
{"input": "abc.xml", "expect": "abc"},
{"input": "./path/to/abc.kts", "expect": "abc"},
}

for _, c := range cases {
if name := SanitizeName(c["input"]); name != c["expect"] {
t.Errorf("result of %s should be %s, instead of %s", c["input"], c["output"], name)
}
}
}