|
|
|
@ -18,6 +18,7 @@ package releaseutil // import "helm.sh/helm/v3/pkg/releaseutil"
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"reflect"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -37,7 +38,7 @@ spec:
|
|
|
|
|
cmd: fake-command
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const expectedManifest = `apiVersion: v1
|
|
|
|
|
const expectedManifest1 = `apiVersion: v1
|
|
|
|
|
kind: Pod
|
|
|
|
|
metadata:
|
|
|
|
|
name: finding-nemo,
|
|
|
|
@ -49,13 +50,99 @@ spec:
|
|
|
|
|
image: fake-image
|
|
|
|
|
cmd: fake-command`
|
|
|
|
|
|
|
|
|
|
const mockManifestFile2 = `
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Pod
|
|
|
|
|
metadata:
|
|
|
|
|
name: finding-nemo,
|
|
|
|
|
annotations:
|
|
|
|
|
"helm.sh/hook": test
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- name: nemo-test
|
|
|
|
|
image: fake-image
|
|
|
|
|
cmd: fake-command
|
|
|
|
|
|
|
|
|
|
---apiVersion: v1
|
|
|
|
|
kind: Pod
|
|
|
|
|
metadata:
|
|
|
|
|
name: finding-nemo-2,
|
|
|
|
|
annotations:
|
|
|
|
|
"helm.sh/hook": test
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- name: nemo-test
|
|
|
|
|
image: fake-image
|
|
|
|
|
cmd: fake-command
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const expectedManifest2 = `apiVersion: v1
|
|
|
|
|
kind: Pod
|
|
|
|
|
metadata:
|
|
|
|
|
name: finding-nemo-2,
|
|
|
|
|
annotations:
|
|
|
|
|
"helm.sh/hook": test
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- name: nemo-test
|
|
|
|
|
image: fake-image
|
|
|
|
|
cmd: fake-command`
|
|
|
|
|
|
|
|
|
|
func TestSplitManifest(t *testing.T) {
|
|
|
|
|
manifests := SplitManifests(mockManifestFile)
|
|
|
|
|
if len(manifests) != 1 {
|
|
|
|
|
t.Errorf("Expected 1 manifest, got %v", len(manifests))
|
|
|
|
|
}
|
|
|
|
|
expected := map[string]string{"manifest-0": expectedManifest}
|
|
|
|
|
expected := map[string]string{"manifest-0": expectedManifest1}
|
|
|
|
|
if !reflect.DeepEqual(manifests, expected) {
|
|
|
|
|
t.Errorf("Expected %v, got %v", expected, manifests)
|
|
|
|
|
t.Errorf("Expected \n%v\n got: \n%v", expected, manifests)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSplitManifestDocBreak(t *testing.T) {
|
|
|
|
|
manifests := SplitManifests(mockManifestFile2)
|
|
|
|
|
if len(manifests) != 2 {
|
|
|
|
|
t.Errorf("Expected 2 manifest, got %v", len(manifests))
|
|
|
|
|
}
|
|
|
|
|
expected := map[string]string{"manifest-0": expectedManifest1, "manifest-1": expectedManifest2}
|
|
|
|
|
if !reflect.DeepEqual(manifests, expected) {
|
|
|
|
|
t.Errorf("Expected \n%v\n got: \n%v", expected, manifests)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSplitManifestNoDocBreak(t *testing.T) {
|
|
|
|
|
manifests := SplitManifests(expectedManifest1)
|
|
|
|
|
if len(manifests) != 1 {
|
|
|
|
|
t.Errorf("Expected 1 manifest, got %v", len(manifests))
|
|
|
|
|
}
|
|
|
|
|
expected := map[string]string{"manifest-0": expectedManifest1}
|
|
|
|
|
if !reflect.DeepEqual(manifests, expected) {
|
|
|
|
|
t.Errorf("Expected \n%v\n got: \n%v", expected, manifests)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createManifest() string {
|
|
|
|
|
sb := strings.Builder{}
|
|
|
|
|
for i := 0; i < 10000; i++ {
|
|
|
|
|
sb.WriteString(expectedManifest2)
|
|
|
|
|
sb.WriteString("\n---")
|
|
|
|
|
}
|
|
|
|
|
return sb.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var BenchmarkSplitManifestsResult map[string]string
|
|
|
|
|
var largeManifest = createManifest()
|
|
|
|
|
|
|
|
|
|
func BenchmarkSplitManifests(b *testing.B) {
|
|
|
|
|
var r map[string]string
|
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
|
r = SplitManifests(largeManifest)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BenchmarkSplitManifestsResult = r
|
|
|
|
|
}
|
|
|
|
|