test(uninstall): add unit test

Signed-off-by: Dong Gang <dong.gang@daocloud.io>
pull/7734/head
Dong Gang 5 years ago
parent 039b99d97d
commit 8521482650

@ -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

@ -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)
}
Loading…
Cancel
Save