From 87d2b7ab678fcff141e19d3f8af8adfecbaa2716 Mon Sep 17 00:00:00 2001 From: Justin Scott Date: Tue, 15 Aug 2017 01:53:18 -0700 Subject: [PATCH] Add test for kind sorter sub sort --- pkg/tiller/kind_sorter_test.go | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pkg/tiller/kind_sorter_test.go b/pkg/tiller/kind_sorter_test.go index ca622f9ae..b7f3bb23f 100644 --- a/pkg/tiller/kind_sorter_test.go +++ b/pkg/tiller/kind_sorter_test.go @@ -147,3 +147,54 @@ func TestKindSorter(t *testing.T) { }) } } + +// TestKindSorterSubSort verifies manifests of same kind are also sorted alphanumeric +func TestKindSorterSubSort(t *testing.T) { + manifests := []manifest{ + { + name: "a", + head: &util.SimpleHead{Kind: "ClusterRole"}, + }, + { + name: "A", + head: &util.SimpleHead{Kind: "ClusterRole"}, + }, + { + name: "0", + head: &util.SimpleHead{Kind: "ConfigMap"}, + }, + { + name: "1", + head: &util.SimpleHead{Kind: "ConfigMap"}, + }, + { + name: "z", + head: &util.SimpleHead{Kind: "ClusterRoleBinding"}, + }, + { + name: "!", + head: &util.SimpleHead{Kind: "ClusterRoleBinding"}, + }, + } + for _, test := range []struct { + description string + order SortOrder + expected string + }{ + {"cm,clusterRole,clusterRoleBinding", InstallOrder, "01Aa!z"}, + } { + var buf bytes.Buffer + t.Run(test.description, func(t *testing.T) { + if got, want := len(test.expected), len(manifests); got != want { + t.Fatalf("Expected %d names in order, got %d", want, got) + } + defer buf.Reset() + for _, r := range sortByKind(manifests, test.order) { + buf.WriteString(r.name) + } + if got := buf.String(); got != test.expected { + t.Errorf("Expected %q, got %q", test.expected, got) + } + }) + } +}