From a21d6ad61f414a4600718a45d4796b4501ebc764 Mon Sep 17 00:00:00 2001 From: Erin Call Date: Wed, 18 Dec 2019 11:47:15 -0800 Subject: [PATCH 1/5] Implement a Delete Step [#4] --- internal/run/delete.go | 52 +++++++++++++ internal/run/delete_test.go | 141 ++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 internal/run/delete.go create mode 100644 internal/run/delete_test.go diff --git a/internal/run/delete.go b/internal/run/delete.go new file mode 100644 index 0000000..7ddc495 --- /dev/null +++ b/internal/run/delete.go @@ -0,0 +1,52 @@ +package run + +import ( + "fmt" +) + +// Delete is an execution step that calls `helm upgrade` when executed. +type Delete struct { + Release string + DryRun bool + + cmd cmd +} + +// Execute executes the `helm upgrade` command. +func (d *Delete) Execute(_ Config) error { + return d.cmd.Run() +} + +// Prepare gets the Delete ready to execute. +func (d *Delete) Prepare(cfg Config) error { + if d.Release == "" { + return fmt.Errorf("release is required") + } + + args := []string{"--kubeconfig", cfg.KubeConfig} + + if cfg.Namespace != "" { + args = append(args, "--namespace", cfg.Namespace) + } + if cfg.Debug { + args = append(args, "--debug") + } + + args = append(args, "delete") + + if d.DryRun { + args = append(args, "--dry-run") + } + + args = append(args, d.Release) + + d.cmd = command(helmBin, args...) + d.cmd.Stdout(cfg.Stdout) + d.cmd.Stderr(cfg.Stderr) + + if cfg.Debug { + fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", d.cmd.String()) + } + + return nil +} diff --git a/internal/run/delete_test.go b/internal/run/delete_test.go new file mode 100644 index 0000000..f9e547d --- /dev/null +++ b/internal/run/delete_test.go @@ -0,0 +1,141 @@ +package run + +import ( + "fmt" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/suite" + "strings" + "testing" +) + +type DeleteTestSuite struct { + suite.Suite + ctrl *gomock.Controller + mockCmd *Mockcmd + actualArgs []string + originalCommand func(string, ...string) cmd +} + +func (suite *DeleteTestSuite) 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 *DeleteTestSuite) AfterTest(_, _ string) { + command = suite.originalCommand +} + +func TestDeleteTestSuite(t *testing.T) { + suite.Run(t, new(DeleteTestSuite)) +} + +func (suite *DeleteTestSuite) TestPrepareAndExecute() { + defer suite.ctrl.Finish() + + d := Delete{ + 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(d.Prepare(cfg)) + expected := []string{"--kubeconfig", "/root/.kube/config", "delete", "zayde_wølf_king"} + suite.Equal(expected, actual) + + d.Execute(cfg) +} + +func (suite *DeleteTestSuite) TestPrepareDryRunFlag() { + d := Delete{ + 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(d.Prepare(cfg)) + expected := []string{"--kubeconfig", "/root/.kube/config", "delete", "--dry-run", "firefox_ak_wildfire"} + suite.Equal(expected, suite.actualArgs) +} + +func (suite *DeleteTestSuite) TestPrepareNamespaceFlag() { + d := Delete{ + 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(d.Prepare(cfg)) + expected := []string{"--kubeconfig", "/root/.kube/config", + "--namespace", "emotion", "delete", "carly_simon_run_away_with_me"} + suite.Equal(expected, suite.actualArgs) +} + +func (suite *DeleteTestSuite) TestPrepareDebugFlag() { + d := Delete{ + 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(d.Prepare(cfg)) + suite.Equal(fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config "+ + "--debug delete just_a_band_huff_and_puff'\n", helmBin), stderr.String()) +} + +func (suite *DeleteTestSuite) 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() + + d := Delete{} + err := d.Prepare(Config{}) + suite.EqualError(err, "release is required", "Delete.Release should be mandatory") +} From f398ee57249fb3d595788bcfd5a5fa42e4e6cc97 Mon Sep 17 00:00:00 2001 From: Erin Call Date: Wed, 18 Dec 2019 16:58:31 -0800 Subject: [PATCH 2/5] Instantiate a Delete when appropriate [#4] "delete" would be a more natural name for the instantiation function, but that's a reserved word in golang. --- internal/helm/plan.go | 21 ++++++++++++++- internal/helm/plan_test.go | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/internal/helm/plan.go b/internal/helm/plan.go index ea184f3..3dc4ce2 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -60,7 +60,7 @@ func determineSteps(cfg Config) *func(Config) []Step { case "upgrade": return &upgrade case "delete": - panic("not implemented") + return &del case "lint": panic("not implemented") case "help": @@ -69,6 +69,8 @@ func determineSteps(cfg Config) *func(Config) []Step { switch cfg.DroneEvent { case "push", "tag", "deployment", "pull_request", "promote", "rollback": return &upgrade + case "delete": + return &del default: panic("not implemented") } @@ -116,6 +118,23 @@ var upgrade = func(cfg Config) []Step { return steps } +var del = func(cfg Config) []Step { + return []Step{ + &run.InitKube{ + SkipTLSVerify: cfg.SkipTLSVerify, + Certificate: cfg.Certificate, + APIServer: cfg.APIServer, + ServiceAccount: cfg.ServiceAccount, + Token: cfg.KubeToken, + TemplateFile: kubeConfigTemplate, + }, + &run.Delete{ + Release: cfg.Release, + DryRun: cfg.DryRun, + }, + } +} + var help = func(cfg Config) []Step { help := &run.Help{} return []Step{help} diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index 716a27c..b975504 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -137,6 +137,43 @@ func (suite *PlanTestSuite) TestUpgrade() { suite.Equal(expected, upgrade) } +func (suite *PlanTestSuite) TestDel() { + cfg := Config{ + KubeToken: "b2YgbXkgYWZmZWN0aW9u", + SkipTLSVerify: true, + Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw", + APIServer: "98.765.43.21", + ServiceAccount: "greathelm", + DryRun: true, + Timeout: "think about what you did", + Release: "jetta_id_love_to_change_the_world", + } + + steps := del(cfg) + suite.Require().Equal(2, len(steps), "del should return 2 steps") + + suite.Require().IsType(&run.InitKube{}, steps[0]) + init, _ := steps[0].(*run.InitKube) + var expected Step = &run.InitKube{ + SkipTLSVerify: true, + Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw", + APIServer: "98.765.43.21", + ServiceAccount: "greathelm", + Token: "b2YgbXkgYWZmZWN0aW9u", + TemplateFile: kubeConfigTemplate, + } + + suite.Equal(expected, init) + + suite.Require().IsType(&run.Delete{}, steps[1]) + actual, _ := steps[1].(*run.Delete) + expected = &run.Delete{ + Release: "jetta_id_love_to_change_the_world", + DryRun: true, + } + suite.Equal(expected, actual) +} + func (suite *PlanTestSuite) TestDeterminePlanUpgradeCommand() { cfg := Config{ Command: "upgrade", @@ -156,6 +193,22 @@ func (suite *PlanTestSuite) TestDeterminePlanUpgradeFromDroneEvent() { } } +func (suite *PlanTestSuite) TestDeterminePlanDeleteCommand() { + cfg := Config{ + Command: "delete", + } + stepsMaker := determineSteps(cfg) + suite.Same(&del, stepsMaker) +} + +func (suite *PlanTestSuite) TestDeterminePlanDeleteFromDroneEvent() { + cfg := Config{ + DroneEvent: "delete", + } + stepsMaker := determineSteps(cfg) + suite.Same(&del, stepsMaker) +} + func (suite *PlanTestSuite) TestDeterminePlanHelpCommand() { cfg := Config{ Command: "help", From 5de156f823bd2806c63544d30f56538c7a395862 Mon Sep 17 00:00:00 2001 From: Erin Call Date: Wed, 18 Dec 2019 17:13:17 -0800 Subject: [PATCH 3/5] Extract Plan's InitKube creation [#4] It's `func initKube` rather than `var initKube = func` because initKube is not meant to be returned by determineSteps. --- internal/helm/plan.go | 35 ++++++++++----------- internal/helm/plan_test.go | 64 +++++++++++++++++++++----------------- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/internal/helm/plan.go b/internal/helm/plan.go index 3dc4ce2..e60389d 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -93,16 +93,7 @@ func (p *Plan) Execute() error { } var upgrade = func(cfg Config) []Step { - steps := make([]Step, 0) - - steps = append(steps, &run.InitKube{ - SkipTLSVerify: cfg.SkipTLSVerify, - Certificate: cfg.Certificate, - APIServer: cfg.APIServer, - ServiceAccount: cfg.ServiceAccount, - Token: cfg.KubeToken, - TemplateFile: kubeConfigTemplate, - }) + steps := initKube(cfg) steps = append(steps, &run.Upgrade{ Chart: cfg.Chart, @@ -119,6 +110,21 @@ var upgrade = func(cfg Config) []Step { } var del = func(cfg Config) []Step { + steps := initKube(cfg) + steps = append(steps, &run.Delete{ + Release: cfg.Release, + DryRun: cfg.DryRun, + }) + + return steps +} + +var help = func(cfg Config) []Step { + help := &run.Help{} + return []Step{help} +} + +func initKube(cfg Config) []Step { return []Step{ &run.InitKube{ SkipTLSVerify: cfg.SkipTLSVerify, @@ -128,14 +134,5 @@ var del = func(cfg Config) []Step { Token: cfg.KubeToken, TemplateFile: kubeConfigTemplate, }, - &run.Delete{ - Release: cfg.Release, - DryRun: cfg.DryRun, - }, } } - -var help = func(cfg Config) []Step { - help := &run.Help{} - return []Step{help} -} diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index b975504..6e293e2 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -87,43 +87,24 @@ func (suite *PlanTestSuite) TestNewPlanAbortsOnError() { func (suite *PlanTestSuite) TestUpgrade() { cfg := Config{ - KubeToken: "cXVlZXIgY2hhcmFjdGVyCg==", - SkipTLSVerify: true, - Certificate: "b2Ygd29rZW5lc3MK", - APIServer: "123.456.78.9", - ServiceAccount: "helmet", - ChartVersion: "seventeen", - DryRun: true, - Wait: true, - ReuseValues: true, - Timeout: "go sit in the corner", - Chart: "billboard_top_100", - Release: "post_malone_circles", - Force: true, + ChartVersion: "seventeen", + DryRun: true, + Wait: true, + ReuseValues: true, + Timeout: "go sit in the corner", + Chart: "billboard_top_100", + Release: "post_malone_circles", + Force: true, } steps := upgrade(cfg) - - suite.Equal(2, len(steps)) - + suite.Require().Equal(2, len(steps), "upgrade should return 2 steps") suite.Require().IsType(&run.InitKube{}, steps[0]) - init, _ := steps[0].(*run.InitKube) - - var expected Step = &run.InitKube{ - SkipTLSVerify: cfg.SkipTLSVerify, - Certificate: cfg.Certificate, - APIServer: cfg.APIServer, - ServiceAccount: cfg.ServiceAccount, - Token: cfg.KubeToken, - TemplateFile: kubeConfigTemplate, - } - - suite.Equal(expected, init) suite.Require().IsType(&run.Upgrade{}, steps[1]) upgrade, _ := steps[1].(*run.Upgrade) - expected = &run.Upgrade{ + expected := &run.Upgrade{ Chart: cfg.Chart, Release: cfg.Release, ChartVersion: cfg.ChartVersion, @@ -174,6 +155,31 @@ func (suite *PlanTestSuite) TestDel() { suite.Equal(expected, actual) } +func (suite *PlanTestSuite) TestInitKube() { + cfg := Config{ + KubeToken: "cXVlZXIgY2hhcmFjdGVyCg==", + SkipTLSVerify: true, + Certificate: "b2Ygd29rZW5lc3MK", + APIServer: "123.456.78.9", + ServiceAccount: "helmet", + } + + steps := initKube(cfg) + suite.Require().Equal(1, len(steps), "initKube should return one step") + suite.Require().IsType(&run.InitKube{}, steps[0]) + init, _ := steps[0].(*run.InitKube) + + expected := &run.InitKube{ + SkipTLSVerify: true, + Certificate: "b2Ygd29rZW5lc3MK", + APIServer: "123.456.78.9", + ServiceAccount: "helmet", + Token: "cXVlZXIgY2hhcmFjdGVyCg==", + TemplateFile: kubeConfigTemplate, + } + suite.Equal(expected, init) +} + func (suite *PlanTestSuite) TestDeterminePlanUpgradeCommand() { cfg := Config{ Command: "upgrade", From 7849b28532ba27496414ec9945a0364842132467 Mon Sep 17 00:00:00 2001 From: Erin Call Date: Thu, 19 Dec 2019 11:11:50 -0800 Subject: [PATCH 4/5] Format the Delete struct less weirdly [#4] I thought it was a golang style convention to put a blank line between public and private struct fields, but apparently I imagined that. --- internal/run/delete.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/run/delete.go b/internal/run/delete.go index 7ddc495..d11c2a6 100644 --- a/internal/run/delete.go +++ b/internal/run/delete.go @@ -8,8 +8,7 @@ import ( type Delete struct { Release string DryRun bool - - cmd cmd + cmd cmd } // Execute executes the `helm upgrade` command. From 161960e55eba2044a4e578cb36cf344d3c1e90cd Mon Sep 17 00:00:00 2001 From: Erin Call Date: Thu, 19 Dec 2019 15:02:49 -0800 Subject: [PATCH 5/5] 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. --- internal/helm/plan.go | 10 ++-- internal/helm/plan_test.go | 23 +++++--- internal/run/delete.go | 51 ------------------ internal/run/uninstall.go | 51 ++++++++++++++++++ .../run/{delete_test.go => uninstall_test.go} | 52 +++++++++---------- 5 files changed, 98 insertions(+), 89 deletions(-) delete mode 100644 internal/run/delete.go create mode 100644 internal/run/uninstall.go rename internal/run/{delete_test.go => uninstall_test.go} (65%) diff --git a/internal/helm/plan.go b/internal/helm/plan.go index e765bbf..1d4ced9 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -59,8 +59,8 @@ func determineSteps(cfg Config) *func(Config) []Step { switch cfg.Command { case "upgrade": return &upgrade - case "delete": - return &del + case "uninstall", "delete": + return &uninstall case "lint": return &lint case "help": @@ -70,7 +70,7 @@ func determineSteps(cfg Config) *func(Config) []Step { case "push", "tag", "deployment", "pull_request", "promote", "rollback": return &upgrade case "delete": - return &del + return &uninstall default: panic("not implemented") } @@ -109,9 +109,9 @@ var upgrade = func(cfg Config) []Step { return steps } -var del = func(cfg Config) []Step { +var uninstall = func(cfg Config) []Step { steps := initKube(cfg) - steps = append(steps, &run.Delete{ + steps = append(steps, &run.Uninstall{ Release: cfg.Release, DryRun: cfg.DryRun, }) diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index 02ca79e..e5a1a96 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -130,8 +130,8 @@ func (suite *PlanTestSuite) TestDel() { Release: "jetta_id_love_to_change_the_world", } - steps := del(cfg) - suite.Require().Equal(2, len(steps), "del should return 2 steps") + steps := uninstall(cfg) + suite.Require().Equal(2, len(steps), "uninstall should return 2 steps") suite.Require().IsType(&run.InitKube{}, steps[0]) init, _ := steps[0].(*run.InitKube) @@ -146,9 +146,9 @@ func (suite *PlanTestSuite) TestDel() { suite.Equal(expected, init) - suite.Require().IsType(&run.Delete{}, steps[1]) - actual, _ := steps[1].(*run.Delete) - expected = &run.Delete{ + suite.Require().IsType(&run.Uninstall{}, steps[1]) + actual, _ := steps[1].(*run.Uninstall) + expected = &run.Uninstall{ Release: "jetta_id_love_to_change_the_world", DryRun: true, } @@ -213,12 +213,21 @@ func (suite *PlanTestSuite) TestDeterminePlanUpgradeFromDroneEvent() { } } +func (suite *PlanTestSuite) TestDeterminePlanUninstallCommand() { + cfg := Config{ + Command: "uninstall", + } + stepsMaker := determineSteps(cfg) + suite.Same(&uninstall, stepsMaker) +} + +// helm_command = delete is provided as an alias for backwards-compatibility with drone-helm func (suite *PlanTestSuite) TestDeterminePlanDeleteCommand() { cfg := Config{ Command: "delete", } stepsMaker := determineSteps(cfg) - suite.Same(&del, stepsMaker) + suite.Same(&uninstall, stepsMaker) } func (suite *PlanTestSuite) TestDeterminePlanDeleteFromDroneEvent() { @@ -226,7 +235,7 @@ func (suite *PlanTestSuite) TestDeterminePlanDeleteFromDroneEvent() { DroneEvent: "delete", } stepsMaker := determineSteps(cfg) - suite.Same(&del, stepsMaker) + suite.Same(&uninstall, stepsMaker) } func (suite *PlanTestSuite) TestDeterminePlanLintCommand() { diff --git a/internal/run/delete.go b/internal/run/delete.go deleted file mode 100644 index d11c2a6..0000000 --- a/internal/run/delete.go +++ /dev/null @@ -1,51 +0,0 @@ -package run - -import ( - "fmt" -) - -// Delete is an execution step that calls `helm upgrade` when executed. -type Delete struct { - Release string - DryRun bool - cmd cmd -} - -// Execute executes the `helm upgrade` command. -func (d *Delete) Execute(_ Config) error { - return d.cmd.Run() -} - -// Prepare gets the Delete ready to execute. -func (d *Delete) Prepare(cfg Config) error { - if d.Release == "" { - return fmt.Errorf("release is required") - } - - args := []string{"--kubeconfig", cfg.KubeConfig} - - if cfg.Namespace != "" { - args = append(args, "--namespace", cfg.Namespace) - } - if cfg.Debug { - args = append(args, "--debug") - } - - args = append(args, "delete") - - if d.DryRun { - args = append(args, "--dry-run") - } - - args = append(args, d.Release) - - d.cmd = command(helmBin, args...) - d.cmd.Stdout(cfg.Stdout) - d.cmd.Stderr(cfg.Stderr) - - if cfg.Debug { - fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", d.cmd.String()) - } - - return nil -} diff --git a/internal/run/uninstall.go b/internal/run/uninstall.go new file mode 100644 index 0000000..1b9d0b2 --- /dev/null +++ b/internal/run/uninstall.go @@ -0,0 +1,51 @@ +package run + +import ( + "fmt" +) + +// Uninstall is an execution step that calls `helm uninstall` when executed. +type Uninstall struct { + Release string + DryRun bool + cmd cmd +} + +// Execute executes the `helm uninstall` command. +func (u *Uninstall) Execute(_ Config) error { + return u.cmd.Run() +} + +// Prepare gets the Uninstall ready to execute. +func (u *Uninstall) Prepare(cfg Config) error { + if u.Release == "" { + return fmt.Errorf("release is required") + } + + args := []string{"--kubeconfig", cfg.KubeConfig} + + if cfg.Namespace != "" { + args = append(args, "--namespace", cfg.Namespace) + } + if cfg.Debug { + args = append(args, "--debug") + } + + args = append(args, "uninstall") + + if u.DryRun { + args = append(args, "--dry-run") + } + + args = append(args, u.Release) + + u.cmd = command(helmBin, args...) + u.cmd.Stdout(cfg.Stdout) + u.cmd.Stderr(cfg.Stderr) + + if cfg.Debug { + fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", u.cmd.String()) + } + + return nil +} diff --git a/internal/run/delete_test.go b/internal/run/uninstall_test.go similarity index 65% rename from internal/run/delete_test.go rename to internal/run/uninstall_test.go index f9e547d..9e826c9 100644 --- a/internal/run/delete_test.go +++ b/internal/run/uninstall_test.go @@ -8,7 +8,7 @@ import ( "testing" ) -type DeleteTestSuite struct { +type UninstallTestSuite struct { suite.Suite ctrl *gomock.Controller mockCmd *Mockcmd @@ -16,7 +16,7 @@ type DeleteTestSuite struct { originalCommand func(string, ...string) cmd } -func (suite *DeleteTestSuite) BeforeTest(_, _ string) { +func (suite *UninstallTestSuite) BeforeTest(_, _ string) { suite.ctrl = gomock.NewController(suite.T()) suite.mockCmd = NewMockcmd(suite.ctrl) @@ -27,18 +27,18 @@ func (suite *DeleteTestSuite) BeforeTest(_, _ string) { } } -func (suite *DeleteTestSuite) AfterTest(_, _ string) { +func (suite *UninstallTestSuite) AfterTest(_, _ string) { command = suite.originalCommand } -func TestDeleteTestSuite(t *testing.T) { - suite.Run(t, new(DeleteTestSuite)) +func TestUninstallTestSuite(t *testing.T) { + suite.Run(t, new(UninstallTestSuite)) } -func (suite *DeleteTestSuite) TestPrepareAndExecute() { +func (suite *UninstallTestSuite) TestPrepareAndExecute() { defer suite.ctrl.Finish() - d := Delete{ + u := Uninstall{ Release: "zayde_wølf_king", } @@ -61,15 +61,15 @@ func (suite *DeleteTestSuite) TestPrepareAndExecute() { cfg := Config{ KubeConfig: "/root/.kube/config", } - suite.NoError(d.Prepare(cfg)) - expected := []string{"--kubeconfig", "/root/.kube/config", "delete", "zayde_wølf_king"} + suite.NoError(u.Prepare(cfg)) + expected := []string{"--kubeconfig", "/root/.kube/config", "uninstall", "zayde_wølf_king"} suite.Equal(expected, actual) - d.Execute(cfg) + u.Execute(cfg) } -func (suite *DeleteTestSuite) TestPrepareDryRunFlag() { - d := Delete{ +func (suite *UninstallTestSuite) TestPrepareDryRunFlag() { + u := Uninstall{ Release: "firefox_ak_wildfire", DryRun: true, } @@ -80,13 +80,13 @@ func (suite *DeleteTestSuite) TestPrepareDryRunFlag() { suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes() suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes() - suite.NoError(d.Prepare(cfg)) - expected := []string{"--kubeconfig", "/root/.kube/config", "delete", "--dry-run", "firefox_ak_wildfire"} + suite.NoError(u.Prepare(cfg)) + expected := []string{"--kubeconfig", "/root/.kube/config", "uninstall", "--dry-run", "firefox_ak_wildfire"} suite.Equal(expected, suite.actualArgs) } -func (suite *DeleteTestSuite) TestPrepareNamespaceFlag() { - d := Delete{ +func (suite *UninstallTestSuite) TestPrepareNamespaceFlag() { + u := Uninstall{ Release: "carly_simon_run_away_with_me", } cfg := Config{ @@ -97,14 +97,14 @@ func (suite *DeleteTestSuite) TestPrepareNamespaceFlag() { suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes() suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes() - suite.NoError(d.Prepare(cfg)) + suite.NoError(u.Prepare(cfg)) expected := []string{"--kubeconfig", "/root/.kube/config", - "--namespace", "emotion", "delete", "carly_simon_run_away_with_me"} + "--namespace", "emotion", "uninstall", "carly_simon_run_away_with_me"} suite.Equal(expected, suite.actualArgs) } -func (suite *DeleteTestSuite) TestPrepareDebugFlag() { - d := Delete{ +func (suite *UninstallTestSuite) TestPrepareDebugFlag() { + u := Uninstall{ Release: "just_a_band_huff_and_puff", } stderr := strings.Builder{} @@ -125,17 +125,17 @@ func (suite *DeleteTestSuite) TestPrepareDebugFlag() { suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes() suite.mockCmd.EXPECT().Stderr(&stderr).AnyTimes() - suite.NoError(d.Prepare(cfg)) + suite.NoError(u.Prepare(cfg)) suite.Equal(fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config "+ - "--debug delete just_a_band_huff_and_puff'\n", helmBin), stderr.String()) + "--debug uninstall just_a_band_huff_and_puff'\n", helmBin), stderr.String()) } -func (suite *DeleteTestSuite) TestPrepareRequiresRelease() { +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() - d := Delete{} - err := d.Prepare(Config{}) - suite.EqualError(err, "release is required", "Delete.Release should be mandatory") + u := Uninstall{} + err := u.Prepare(Config{}) + suite.EqualError(err, "release is required", "Uninstall.Release should be mandatory") }