diff --git a/cmd/drone-helm/main.go b/cmd/drone-helm/main.go index 43d2e30..cf0b0e6 100644 --- a/cmd/drone-helm/main.go +++ b/cmd/drone-helm/main.go @@ -27,7 +27,7 @@ func main() { // Expect the plan to go off the rails if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "%s\n", err.Error()) // Throw away the plan os.Exit(1) } diff --git a/internal/helm/plan.go b/internal/helm/plan.go index 0a20969..ebd4774 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -74,7 +74,7 @@ func determineSteps(cfg Config) *func(Config) []Step { case "delete": return &uninstall default: - panic("not implemented") + return &help } } } @@ -140,7 +140,9 @@ var lint = func(cfg Config) []Step { } var help = func(cfg Config) []Step { - help := &run.Help{} + help := &run.Help{ + HelmCommand: cfg.Command, + } return []Step{help} } diff --git a/internal/run/help.go b/internal/run/help.go index 8597815..f2d6c59 100644 --- a/internal/run/help.go +++ b/internal/run/help.go @@ -6,12 +6,20 @@ import ( // Help is a step in a helm Plan that calls `helm help`. type Help struct { - cmd cmd + HelmCommand string + cmd cmd } // Execute executes the `helm help` command. -func (h *Help) Execute(_ Config) error { - return h.cmd.Run() +func (h *Help) Execute(cfg Config) error { + if err := h.cmd.Run(); err != nil { + return fmt.Errorf("while running '%s': %w", h.cmd.String(), err) + } + + if h.HelmCommand == "help" { + return nil + } + return fmt.Errorf("unknown command '%s'", h.HelmCommand) } // Prepare gets the Help ready to execute. diff --git a/internal/run/help_test.go b/internal/run/help_test.go index 1824578..19c49d2 100644 --- a/internal/run/help_test.go +++ b/internal/run/help_test.go @@ -38,9 +38,6 @@ func (suite *HelpTestSuite) TestPrepare() { Stdout(&stdout) mCmd.EXPECT(). Stderr(&stderr) - mCmd.EXPECT(). - Run(). - Times(1) cfg := Config{ Stdout: &stdout, @@ -49,8 +46,32 @@ func (suite *HelpTestSuite) TestPrepare() { h := Help{} err := h.Prepare(cfg) - suite.Require().Nil(err) - h.Execute(cfg) + suite.NoError(err) +} + +func (suite *HelpTestSuite) TestExecute() { + ctrl := gomock.NewController(suite.T()) + defer ctrl.Finish() + mCmd := NewMockcmd(ctrl) + originalCommand := command + command = func(_ string, _ ...string) cmd { + return mCmd + } + defer func() { command = originalCommand }() + + mCmd.EXPECT(). + Run(). + Times(2) + + cfg := Config{} + help := Help{ + HelmCommand: "help", + cmd: mCmd, + } + suite.NoError(help.Execute(cfg)) + + help.HelmCommand = "get down on friday" + suite.EqualError(help.Execute(cfg), "unknown command 'get down on friday'") } func (suite *HelpTestSuite) TestPrepareDebugFlag() {