...
1
16
17 package action
18
19 import (
20 "fmt"
21 "testing"
22
23 "github.com/stretchr/testify/assert"
24
25 kubefake "helm.sh/helm/v3/pkg/kube/fake"
26 "helm.sh/helm/v3/pkg/release"
27 )
28
29 func uninstallAction(t *testing.T) *Uninstall {
30 config := actionConfigFixture(t)
31 unAction := NewUninstall(config)
32 return unAction
33 }
34
35 func TestUninstallRelease_ignoreNotFound(t *testing.T) {
36 unAction := uninstallAction(t)
37 unAction.DryRun = false
38 unAction.IgnoreNotFound = true
39
40 is := assert.New(t)
41 res, err := unAction.Run("release-non-exist")
42 is.Nil(res)
43 is.NoError(err)
44 }
45
46 func TestUninstallRelease_deleteRelease(t *testing.T) {
47 is := assert.New(t)
48
49 unAction := uninstallAction(t)
50 unAction.DisableHooks = true
51 unAction.DryRun = false
52 unAction.KeepHistory = true
53
54 rel := releaseStub()
55 rel.Name = "keep-secret"
56 rel.Manifest = `{
57 "apiVersion": "v1",
58 "kind": "Secret",
59 "metadata": {
60 "name": "secret",
61 "annotations": {
62 "helm.sh/resource-policy": "keep"
63 }
64 },
65 "type": "Opaque",
66 "data": {
67 "password": "password"
68 }
69 }`
70 unAction.cfg.Releases.Create(rel)
71 res, err := unAction.Run(rel.Name)
72 is.NoError(err)
73 expected := `These resources were kept due to the resource policy:
74 [Secret] secret
75 `
76 is.Contains(res.Info, expected)
77 }
78
79 func TestUninstallRelease_Wait(t *testing.T) {
80 is := assert.New(t)
81
82 unAction := uninstallAction(t)
83 unAction.DisableHooks = true
84 unAction.DryRun = false
85 unAction.Wait = true
86
87 rel := releaseStub()
88 rel.Name = "come-fail-away"
89 rel.Manifest = `{
90 "apiVersion": "v1",
91 "kind": "Secret",
92 "metadata": {
93 "name": "secret"
94 },
95 "type": "Opaque",
96 "data": {
97 "password": "password"
98 }
99 }`
100 unAction.cfg.Releases.Create(rel)
101 failer := unAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
102 failer.WaitError = fmt.Errorf("U timed out")
103 unAction.cfg.KubeClient = failer
104 res, err := unAction.Run(rel.Name)
105 is.Error(err)
106 is.Contains(err.Error(), "U timed out")
107 is.Equal(res.Release.Info.Status, release.StatusUninstalled)
108 }
109
110 func TestUninstallRelease_Cascade(t *testing.T) {
111 is := assert.New(t)
112
113 unAction := uninstallAction(t)
114 unAction.DisableHooks = true
115 unAction.DryRun = false
116 unAction.Wait = false
117 unAction.DeletionPropagation = "foreground"
118
119 rel := releaseStub()
120 rel.Name = "come-fail-away"
121 rel.Manifest = `{
122 "apiVersion": "v1",
123 "kind": "Secret",
124 "metadata": {
125 "name": "secret"
126 },
127 "type": "Opaque",
128 "data": {
129 "password": "password"
130 }
131 }`
132 unAction.cfg.Releases.Create(rel)
133 failer := unAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
134 failer.DeleteWithPropagationError = fmt.Errorf("Uninstall with cascade failed")
135 failer.BuildDummy = true
136 unAction.cfg.KubeClient = failer
137 _, err := unAction.Run(rel.Name)
138 is.Error(err)
139 is.Contains(err.Error(), "failed to delete release: come-fail-away")
140 }
141
View as plain text