Skip to content

Commit

Permalink
Remove the "./" prefix before sanitizing the integration name. (apach…
Browse files Browse the repository at this point in the history
…e#309)

Makes the paths like "./integration_name.java" work

Add the unit test file for the sanitization
  • Loading branch information
crystaldust authored and ipolyzos committed Jul 31, 2019
1 parent 54953df commit babc13c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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)
}
}
}

0 comments on commit babc13c

Please sign in to comment.