Merge pull request #7266 from bradskuse/kind-sorter-helm3

Fix: helm3 - kind sorter incorrectly compares unknown and namespace
pull/7358/head
Matthew Fisher 5 years ago committed by GitHub
commit 8c84a0bc03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -134,11 +134,13 @@ func (k *kindSorter) Less(i, j int) bool {
b := k.manifests[j]
first, aok := k.ordering[a.Head.Kind]
second, bok := k.ordering[b.Head.Kind]
if first == second {
// if both are unknown and of different kind sort by kind alphabetically
if !aok && !bok && a.Head.Kind != b.Head.Kind {
if !aok && !bok {
// if both are unknown then sort alphabetically by kind, keep original order if same kind
if a.Head.Kind != b.Head.Kind {
return a.Head.Kind < b.Head.Kind
}
return first < second
}
// unknown kind is last
if !aok {

@ -245,3 +245,24 @@ func TestKindSorterKeepOriginalOrder(t *testing.T) {
})
}
}
func TestKindSorterNamespaceAgainstUnknown(t *testing.T) {
unknown := Manifest{
Name: "a",
Head: &SimpleHead{Kind: "Unknown"},
}
namespace := Manifest{
Name: "b",
Head: &SimpleHead{Kind: "Namespace"},
}
manifests := []Manifest{unknown, namespace}
sortByKind(manifests, InstallOrder)
expectedOrder := []Manifest{namespace, unknown}
for i, manifest := range manifests {
if expectedOrder[i].Name != manifest.Name {
t.Errorf("Expected %s, got %s", expectedOrder[i].Name, manifest.Name)
}
}
}

Loading…
Cancel
Save