Rename Delete to Uninstall [#4]
Helm3 renamed its delete command to uninstall. We should still accept helm_command=delete for drone-helm compatibility, but the internals should use Helm's preferred name.
This commit is contained in:
141
internal/run/uninstall_test.go
Normal file
141
internal/run/uninstall_test.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type UninstallTestSuite struct {
|
||||
suite.Suite
|
||||
ctrl *gomock.Controller
|
||||
mockCmd *Mockcmd
|
||||
actualArgs []string
|
||||
originalCommand func(string, ...string) cmd
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) BeforeTest(_, _ string) {
|
||||
suite.ctrl = gomock.NewController(suite.T())
|
||||
suite.mockCmd = NewMockcmd(suite.ctrl)
|
||||
|
||||
suite.originalCommand = command
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.actualArgs = args
|
||||
return suite.mockCmd
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) AfterTest(_, _ string) {
|
||||
command = suite.originalCommand
|
||||
}
|
||||
|
||||
func TestUninstallTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(UninstallTestSuite))
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
u := Uninstall{
|
||||
Release: "zayde_wølf_king",
|
||||
}
|
||||
|
||||
actual := []string{}
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
actual = args
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().
|
||||
Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().
|
||||
Stderr(gomock.Any())
|
||||
suite.mockCmd.EXPECT().
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
}
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
expected := []string{"--kubeconfig", "/root/.kube/config", "uninstall", "zayde_wølf_king"}
|
||||
suite.Equal(expected, actual)
|
||||
|
||||
u.Execute(cfg)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareDryRunFlag() {
|
||||
u := Uninstall{
|
||||
Release: "firefox_ak_wildfire",
|
||||
DryRun: true,
|
||||
}
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
expected := []string{"--kubeconfig", "/root/.kube/config", "uninstall", "--dry-run", "firefox_ak_wildfire"}
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareNamespaceFlag() {
|
||||
u := Uninstall{
|
||||
Release: "carly_simon_run_away_with_me",
|
||||
}
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Namespace: "emotion",
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
expected := []string{"--kubeconfig", "/root/.kube/config",
|
||||
"--namespace", "emotion", "uninstall", "carly_simon_run_away_with_me"}
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareDebugFlag() {
|
||||
u := Uninstall{
|
||||
Release: "just_a_band_huff_and_puff",
|
||||
}
|
||||
stderr := strings.Builder{}
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Debug: true,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.mockCmd.EXPECT().
|
||||
String().
|
||||
Return(fmt.Sprintf("%s %s", path, strings.Join(args, " ")))
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(&stderr).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
suite.Equal(fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config "+
|
||||
"--debug uninstall just_a_band_huff_and_puff'\n", helmBin), stderr.String())
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareRequiresRelease() {
|
||||
// These aren't really expected, but allowing them gives clearer test-failure messages
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
u := Uninstall{}
|
||||
err := u.Prepare(Config{})
|
||||
suite.EqualError(err, "release is required", "Uninstall.Release should be mandatory")
|
||||
}
|
||||
Reference in New Issue
Block a user