mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Merge pull request #528 from laverya/fallback-to-string-sort-in-gvk-comparison-if-indices-equal
add fallback for GVK comparison
This commit is contained in:
@@ -97,7 +97,9 @@ func (x Gvk) IsLessThan(o Gvk) bool {
|
||||
indexI, foundI := typeOrders[x.Kind]
|
||||
indexJ, foundJ := typeOrders[o.Kind]
|
||||
if foundI && foundJ {
|
||||
return indexI < indexJ
|
||||
if indexI != indexJ {
|
||||
return indexI < indexJ
|
||||
}
|
||||
}
|
||||
if foundI && !foundJ {
|
||||
return true
|
||||
|
||||
@@ -48,6 +48,16 @@ var lessThanTests = []struct {
|
||||
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
|
||||
{Gvk{Group: "a", Version: "b", Kind: "a"},
|
||||
Gvk{Group: "a", Version: "b", Kind: "b"}},
|
||||
{Gvk{Group: "a", Version: "b", Kind: "Namespace"},
|
||||
Gvk{Group: "a", Version: "c", Kind: "Namespace"}},
|
||||
{Gvk{Group: "a", Version: "c", Kind: "Namespace"},
|
||||
Gvk{Group: "b", Version: "c", Kind: "Namespace"}},
|
||||
{Gvk{Group: "b", Version: "c", Kind: "Namespace"},
|
||||
Gvk{Group: "a", Version: "c", Kind: "ClusterRole"}},
|
||||
{Gvk{Group: "a", Version: "c", Kind: "Namespace"},
|
||||
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
|
||||
{Gvk{Group: "a", Version: "d", Kind: "Namespace"},
|
||||
Gvk{Group: "b", Version: "c", Kind: "Namespace"}},
|
||||
}
|
||||
|
||||
func TestIsLessThan1(t *testing.T) {
|
||||
@@ -55,6 +65,9 @@ func TestIsLessThan1(t *testing.T) {
|
||||
if !hey.x1.IsLessThan(hey.x2) {
|
||||
t.Fatalf("%v should be less than %v", hey.x1, hey.x2)
|
||||
}
|
||||
if hey.x2.IsLessThan(hey.x1) {
|
||||
t.Fatalf("%v should not be less than %v", hey.x2, hey.x1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user