From 85214826502054d1d96dd3ab6882388357dd281d Mon Sep 17 00:00:00 2001 From: Dong Gang Date: Fri, 10 Jul 2020 09:57:10 +0800 Subject: [PATCH] test(uninstall): add unit test Signed-off-by: Dong Gang --- pkg/action/action_test.go | 23 +++++++++++++++++++++++ pkg/action/uninstall_test.go | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 pkg/action/uninstall_test.go diff --git a/pkg/action/action_test.go b/pkg/action/action_test.go index 36ef261a3..804f0ea80 100644 --- a/pkg/action/action_test.go +++ b/pkg/action/action_test.go @@ -137,6 +137,20 @@ subjects: namespace: {{ .Release.Namespace }} ` +var manifestWithKeepAnno = ` +apiVersion: v1 +kind: Pod +metadata: + name: pod-keep, + annotations: + "helm.sh/resource-policy": keep +spec: + containers: + - name: nemo-test + image: fake-image + cmd: fake-command + ` + type chartOptions struct { *chart.Chart } @@ -253,6 +267,15 @@ func withMultipleManifestTemplate() chartOption { } } +func withKeepAnnoManifestTemplate() chartOption { + return func(opts *chartOptions) { + sampleTemplates := []*chart.File{ + {Name: "templates/keep", Data: []byte(manifestWithKeepAnno)}, + } + opts.Templates = append(opts.Templates, sampleTemplates...) + } +} + func withKube(version string) chartOption { return func(opts *chartOptions) { opts.Metadata.KubeVersion = version diff --git a/pkg/action/uninstall_test.go b/pkg/action/uninstall_test.go new file mode 100644 index 000000000..7fe649464 --- /dev/null +++ b/pkg/action/uninstall_test.go @@ -0,0 +1,19 @@ +package action + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestUninstall_deleteRelease(t *testing.T) { + is := assert.New(t) + rel := releaseStub() + rel.Chart =buildChart(withKeepAnnoManifestTemplate()) + rel.Manifest = manifestWithKeepAnno + config := actionConfigFixture(t) + unisAction := NewUninstall(config) + str, errs := unisAction.deleteRelease(rel) + is.Len(errs,0) + is.Equal("pod/pod-keep\n",str) +}