Fix: helm3 - kind sorter incorrectly compares unknown and namespace

Signed-off-by: Bradley Skuse <bradleyskuse@me.com>

Fix style error from CI

Signed-off-by: Bradley Skuse <bradleyskuse@me.com>

Fix: helm3 - kind sorter incorrectly compares unknown and namespace

Fix: helm3 - kind sorter incorrectly compares unknown and namespace

Fix: helm3 - kind sorter incorrectly compares unknown and namespace
(cherry picked from commit e2946c7e34)
release-3.0
Bradley Skuse 6 years ago committed by Matt Farina
parent d2c8c71d50
commit 86839f2490
No known key found for this signature in database
GPG Key ID: 9436E80BFBA46909

@ -134,13 +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 same kind (including unknown) sub sort alphanumeric
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 a.Name < b.Name
return first < second
}
// unknown kind is last
if !aok {

@ -245,3 +245,24 @@ func TestKindSorterSubSort(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