helm/pkg/cmd/uninstall_test.go
Hidde Beydals 2f1ecc7100
fix(uninstall): supersede deployed releases
This ensures that when `helm uninstall` is run with `--keep-history`
any release in a `deployed` state other than the last release (e.g.
due to a failed upgrade) is being marked as `superseded`.

As a by-effect, running `helm upgrade` on a release which has been
uninstalled after an upgrade failure now no longer works. But instead
fails with a `"<name>" has no deployed releases` error. Which is the
(likely) intended behavior, and prevents other side-effects like
rolling back to a release version which happened before the uninstall
if `--atomic` (or `--rollback-on-failure`) was provided.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2025-11-07 23:09:48 +01:00

93 lines
2.9 KiB
Go

/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
"testing"
"helm.sh/helm/v4/pkg/release/common"
release "helm.sh/helm/v4/pkg/release/v1"
)
func TestUninstall(t *testing.T) {
tests := []cmdTestCase{
{
name: "basic uninstall",
cmd: "uninstall aeneas",
golden: "output/uninstall.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "aeneas"})},
},
{
name: "multiple uninstall",
cmd: "uninstall aeneas aeneas2",
golden: "output/uninstall-multiple.txt",
rels: []*release.Release{
release.Mock(&release.MockReleaseOptions{Name: "aeneas"}),
release.Mock(&release.MockReleaseOptions{Name: "aeneas2"}),
},
},
{
name: "uninstall with timeout",
cmd: "uninstall aeneas --timeout 120s",
golden: "output/uninstall-timeout.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "aeneas"})},
},
{
name: "uninstall without hooks",
cmd: "uninstall aeneas --no-hooks",
golden: "output/uninstall-no-hooks.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "aeneas"})},
},
{
name: "keep history",
cmd: "uninstall aeneas --keep-history",
golden: "output/uninstall-keep-history.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "aeneas"})},
},
{
name: "keep history with earlier deployed release",
cmd: "uninstall aeneas --keep-history",
golden: "output/uninstall-keep-history-earlier-deployed.txt",
rels: []*release.Release{
release.Mock(&release.MockReleaseOptions{Name: "aeneas", Version: 1, Status: common.StatusDeployed}),
release.Mock(&release.MockReleaseOptions{Name: "aeneas", Version: 2, Status: common.StatusFailed}),
},
},
{
name: "wait",
cmd: "uninstall aeneas --wait",
golden: "output/uninstall-wait.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "aeneas"})},
},
{
name: "uninstall without release",
cmd: "uninstall",
golden: "output/uninstall-no-args.txt",
wantError: true,
},
}
runTestCmd(t, tests)
}
func TestUninstallCompletion(t *testing.T) {
checkReleaseCompletion(t, "uninstall", true)
}
func TestUninstallFileCompletion(t *testing.T) {
checkFileCompletion(t, "uninstall", false)
checkFileCompletion(t, "uninstall myrelease", false)
}