|
|
@ -19,6 +19,8 @@ package releaseutil
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v3/pkg/release"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestKindSorter(t *testing.T) {
|
|
|
|
func TestKindSorter(t *testing.T) {
|
|
|
@ -175,12 +177,18 @@ func TestKindSorter(t *testing.T) {
|
|
|
|
t.Fatalf("Expected %d names in order, got %d", want, got)
|
|
|
|
t.Fatalf("Expected %d names in order, got %d", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer buf.Reset()
|
|
|
|
defer buf.Reset()
|
|
|
|
for _, r := range sortByKind(manifests, test.order) {
|
|
|
|
orig := manifests
|
|
|
|
|
|
|
|
for _, r := range sortManifestsByKind(manifests, test.order) {
|
|
|
|
buf.WriteString(r.Name)
|
|
|
|
buf.WriteString(r.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if got := buf.String(); got != test.expected {
|
|
|
|
if got := buf.String(); got != test.expected {
|
|
|
|
t.Errorf("Expected %q, got %q", test.expected, got)
|
|
|
|
t.Errorf("Expected %q, got %q", test.expected, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, manifest := range orig {
|
|
|
|
|
|
|
|
if manifest != manifests[i] {
|
|
|
|
|
|
|
|
t.Fatal("Expected input to sortManifestsByKind to stay the same")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -236,7 +244,7 @@ func TestKindSorterKeepOriginalOrder(t *testing.T) {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
var buf bytes.Buffer
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
defer buf.Reset()
|
|
|
|
defer buf.Reset()
|
|
|
|
for _, r := range sortByKind(manifests, test.order) {
|
|
|
|
for _, r := range sortManifestsByKind(manifests, test.order) {
|
|
|
|
buf.WriteString(r.Name)
|
|
|
|
buf.WriteString(r.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if got := buf.String(); got != test.expected {
|
|
|
|
if got := buf.String(); got != test.expected {
|
|
|
@ -257,7 +265,7 @@ func TestKindSorterNamespaceAgainstUnknown(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
manifests := []Manifest{unknown, namespace}
|
|
|
|
manifests := []Manifest{unknown, namespace}
|
|
|
|
sortByKind(manifests, InstallOrder)
|
|
|
|
manifests = sortManifestsByKind(manifests, InstallOrder)
|
|
|
|
|
|
|
|
|
|
|
|
expectedOrder := []Manifest{namespace, unknown}
|
|
|
|
expectedOrder := []Manifest{namespace, unknown}
|
|
|
|
for i, manifest := range manifests {
|
|
|
|
for i, manifest := range manifests {
|
|
|
@ -266,3 +274,54 @@ func TestKindSorterNamespaceAgainstUnknown(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// test hook sorting with a small subset of kinds, since it uses the same algorithm as sortManifestsByKind
|
|
|
|
|
|
|
|
func TestKindSorterForHooks(t *testing.T) {
|
|
|
|
|
|
|
|
hooks := []*release.Hook{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "i",
|
|
|
|
|
|
|
|
Kind: "ClusterRole",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "j",
|
|
|
|
|
|
|
|
Kind: "ClusterRoleBinding",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "c",
|
|
|
|
|
|
|
|
Kind: "LimitRange",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "a",
|
|
|
|
|
|
|
|
Kind: "Namespace",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range []struct {
|
|
|
|
|
|
|
|
description string
|
|
|
|
|
|
|
|
order KindSortOrder
|
|
|
|
|
|
|
|
expected string
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{"install", InstallOrder, "acij"},
|
|
|
|
|
|
|
|
{"uninstall", UninstallOrder, "jica"},
|
|
|
|
|
|
|
|
} {
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
|
|
|
|
if got, want := len(test.expected), len(hooks); got != want {
|
|
|
|
|
|
|
|
t.Fatalf("Expected %d names in order, got %d", want, got)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer buf.Reset()
|
|
|
|
|
|
|
|
orig := hooks
|
|
|
|
|
|
|
|
for _, r := range sortHooksByKind(hooks, test.order) {
|
|
|
|
|
|
|
|
buf.WriteString(r.Name)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, hook := range orig {
|
|
|
|
|
|
|
|
if hook != hooks[i] {
|
|
|
|
|
|
|
|
t.Fatal("Expected input to sortHooksByKind to stay the same")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if got := buf.String(); got != test.expected {
|
|
|
|
|
|
|
|
t.Errorf("Expected %q, got %q", test.expected, got)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|