test for unknown kinds

Signed-off-by: Lyndon Shi <shilyndon@outlook.com>
pull/12495/head
Lyndon Shi 9 months ago
parent ca2390a181
commit d6f9e81941

@ -125,15 +125,13 @@ func (x hookByWeight) Less(i, j int) bool {
first, iok := ordering[x[i].Kind]
second, jok := ordering[x[j].Kind]
// As in https://github.com/helm/helm/blob/fe595b69d78b213ab181d98ce24dde2454a56f9d/pkg/releaseutil/kind_sorter.go#L145C15-L145C15
if !iok && !jok {
// If both are unknown then sort alphabetically by kind.
if x[i].Kind != x[j].Kind {
return x[i].Kind < x[j].Kind
// Sort unknown kinds alphabetically, with name as the tiebreaker.
if x[i].Kind == x[j].Kind {
return x[i].Name < x[j].Name
}
// Otherwise, let Stable() preserve the original order.
return false
return x[i].Kind < x[j].Kind
}
// Unknown kind is last.

@ -31,6 +31,9 @@ func TestHookByWeight(t *testing.T) {
{Weight: 1, Kind: "ServiceAccount", Name: "ServiceAccountB"},
{Weight: 1, Kind: "ServiceAccount", Name: "ServiceAccountA"},
{Weight: 0, Kind: "Job", Name: "Job"},
{Weight: 0, Kind: "UnknownB", Name: "UnknownB1"},
{Weight: 0, Kind: "UnknownB", Name: "UnknownB0"},
{Weight: 0, Kind: "UnknownA", Name: "UnknownA"},
{Weight: -1, Kind: "APIService", Name: "APIServiceB"},
{Weight: -1, Kind: "APIService", Name: "APIServiceA"},
}
@ -41,6 +44,9 @@ func TestHookByWeight(t *testing.T) {
{Weight: -1, Kind: "APIService", Name: "APIServiceA"},
{Weight: -1, Kind: "APIService", Name: "APIServiceB"},
{Weight: 0, Kind: "Job", Name: "Job"},
{Weight: 0, Kind: "UnknownA", Name: "UnknownA"},
{Weight: 0, Kind: "UnknownB", Name: "UnknownB0"},
{Weight: 0, Kind: "UnknownB", Name: "UnknownB1"},
{Weight: 1, Kind: "ServiceAccount", Name: "ServiceAccountA"},
{Weight: 1, Kind: "ServiceAccount", Name: "ServiceAccountB"},
{Weight: 1, Kind: "Pod", Name: "PodA"},
@ -62,6 +68,8 @@ func TestHookByWeight_KindSorted(t *testing.T) {
{Weight: -1, Kind: "Pod", Name: "podA"},
{Weight: 0, Kind: "Job", Name: "Job"},
{Weight: 1, Kind: "APIService", Name: "APIServiceA"},
{Weight: 0, Kind: "UnknownA", Name: "Unknown1"},
{Weight: 0, Kind: "UnknownB", Name: "Unknown0"},
}
sort.Stable(hookByWeight(hooks))
@ -70,6 +78,8 @@ func TestHookByWeight_KindSorted(t *testing.T) {
{Weight: -1, Kind: "Pod", Name: "podA"},
{Weight: 0, Kind: "Pod", Name: "podB"},
{Weight: 0, Kind: "Job", Name: "Job"},
{Weight: 0, Kind: "UnknownA", Name: "Unknown1"},
{Weight: 0, Kind: "UnknownB", Name: "Unknown0"},
{Weight: 1, Kind: "ServiceAccount", Name: "ServiceAccountA"},
{Weight: 1, Kind: "ServiceAccount", Name: "ServiceAccountB"},
{Weight: 1, Kind: "APIService", Name: "APIServiceA"},

Loading…
Cancel
Save