Merge branch 'master' into helm-repos

This commit is contained in:
Erin Call 2019-12-30 13:29:23 -08:00 committed by GitHub
commit 3985ec8faa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 11 deletions

View file

@ -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)
}

View file

@ -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}
}

View file

@ -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.

View file

@ -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() {