зеркало из https://github.com/Azure/orkestra.git
Fix bug where IsFileYaml() returns true if non yaml file's extension contains suffix yaml or yml (#327)
* Fix IsFileYaml bug * Fix typo
This commit is contained in:
Родитель
9ada8f1343
Коммит
ec6c417c8c
|
@ -83,7 +83,7 @@ func TemplateContainsYaml(ch *chart.Chart) (bool, error) {
|
|||
|
||||
func IsFileYaml(f string) bool {
|
||||
f = strings.ToLower(f)
|
||||
if strings.HasSuffix(f, "yml") || strings.HasSuffix(f, "yaml") {
|
||||
if strings.HasSuffix(f, ".yml") || strings.HasSuffix(f, ".yaml") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
|
@ -117,3 +117,64 @@ func TestTruncateString(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsFileYaml(t *testing.T) {
|
||||
type args struct {
|
||||
f string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "testing empty",
|
||||
args: args{
|
||||
f: "",
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "testing .yaml file",
|
||||
args: args{
|
||||
f: "templates/filename.yaml",
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "testing .yml file",
|
||||
args: args{
|
||||
f: "templates/bin/myfile.yml",
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "testing .yaml file",
|
||||
args: args{
|
||||
f: "templates/bin/myfile.txt",
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "testing filename extension that contains yaml but not yaml file",
|
||||
args: args{
|
||||
f: "templates/bin/myfile.myyaml",
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "testing .txt file with name containing yaml substring.",
|
||||
args: args{
|
||||
f: "templates/bin/yamlFileGuide.txt",
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := IsFileYaml(tt.args.f); got != tt.want {
|
||||
t.Errorf("IsFileYaml() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче