MCPcopy
hub / github.com/helm/helm / TestUpgradeRelease_RollbackOnFailure

Function TestUpgradeRelease_RollbackOnFailure

pkg/action/upgrade_test.go:159–212  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestUpgradeRelease_RollbackOnFailure(t *testing.T) {
160 is := assert.New(t)
161 req := require.New(t)
162
163 t.Run("rollback-on-failure rollback succeeds", func(t *testing.T) {
164 upAction := upgradeAction(t)
165
166 rel := releaseStub()
167 rel.Name = "nuketown"
168 rel.Info.Status = common.StatusDeployed
169 require.NoError(t, upAction.cfg.Releases.Create(rel))
170
171 failer := upAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
172 // We can't make Update error because then the rollback won't work
173 failer.WatchUntilReadyError = errors.New("arming key removed")
174 upAction.cfg.KubeClient = failer
175 upAction.RollbackOnFailure = true
176 vals := map[string]any{}
177
178 resi, err := upAction.Run(rel.Name, buildChart(), vals)
179 req.Error(err)
180 is.Contains(err.Error(), "arming key removed")
181 is.Contains(err.Error(), "rollback-on-failure")
182 res, err := releaserToV1Release(resi)
183 is.NoError(err)
184
185 // Now make sure it is actually upgraded
186 updatedResi, err := upAction.cfg.Releases.Get(res.Name, 3)
187 is.NoError(err)
188 updatedRes, err := releaserToV1Release(updatedResi)
189 is.NoError(err)
190 // Should have rolled back to the previous
191 is.Equal(updatedRes.Info.Status, common.StatusDeployed)
192 })
193
194 t.Run("rollback-on-failure uninstall fails", func(t *testing.T) {
195 upAction := upgradeAction(t)
196 rel := releaseStub()
197 rel.Name = "fallout"
198 rel.Info.Status = common.StatusDeployed
199 require.NoError(t, upAction.cfg.Releases.Create(rel))
200
201 failer := upAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
202 failer.UpdateError = errors.New("update fail")
203 upAction.cfg.KubeClient = failer
204 upAction.RollbackOnFailure = true
205 vals := map[string]any{}
206
207 _, err := upAction.Run(rel.Name, buildChart(), vals)
208 req.Error(err)
209 is.Contains(err.Error(), "update fail")
210 is.Contains(err.Error(), "an error occurred while rolling back the release")
211 })
212}
213
214func TestUpgradeRelease_ReuseValues(t *testing.T) {
215 is := assert.New(t)

Callers

nothing calls this directly

Calls 9

upgradeActionFunction · 0.85
buildChartFunction · 0.85
ContainsMethod · 0.80
releaseStubFunction · 0.70
releaserToV1ReleaseFunction · 0.70
RunMethod · 0.65
CreateMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…