mirror of https://github.com/helm/helm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
64 lines
1.8 KiB
/*
|
|
Copyright The Helm Authors.
|
|
|
|
Licensed 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 v2
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateDependency(t *testing.T) {
|
|
dep := &Dependency{
|
|
Name: "example",
|
|
}
|
|
for value, shouldFail := range map[string]bool{
|
|
"abcdefghijklmenopQRSTUVWXYZ-0123456780_": false,
|
|
"-okay": false,
|
|
"_okay": false,
|
|
"- bad": true,
|
|
" bad": true,
|
|
"bad\nvalue": true,
|
|
"bad ": true,
|
|
"bad$": true,
|
|
} {
|
|
dep.Alias = value
|
|
res := dep.Validate()
|
|
if res != nil && !shouldFail {
|
|
t.Errorf("Failed on case %q", dep.Alias)
|
|
} else if res == nil && shouldFail {
|
|
t.Errorf("Expected failure for %q", dep.Alias)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidateDependency_SanitizesDependsOn(t *testing.T) {
|
|
dep := &Dependency{
|
|
Name: "example",
|
|
DependsOn: []string{"data\abase", "cache\rqueue"},
|
|
}
|
|
if err := dep.Validate(); err != nil {
|
|
t.Fatalf("unexpected error: %s", err)
|
|
}
|
|
// Sanitized like Name/Tags/Condition: non-printable runes are dropped and
|
|
// whitespace runes are normalized to spaces, so stray characters don't break
|
|
// subchart depends-on lookups.
|
|
if dep.DependsOn[0] != "database" {
|
|
t.Errorf("DependsOn[0] not sanitized: got %q, want %q", dep.DependsOn[0], "database")
|
|
}
|
|
if dep.DependsOn[1] != "cache queue" {
|
|
t.Errorf("DependsOn[1] not sanitized: got %q, want %q", dep.DependsOn[1], "cache queue")
|
|
}
|
|
}
|