Implement the debug flag and help command
I'm vacillating about the choice to have separate Config structs in the `helm` and `run` packages. I can't tell whether it's "good separation of concerns" or "cumbersome and over-engineered." It seems appropriate at the moment, though.
This commit is contained in:
@@ -1,33 +1,72 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHelp(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
type HelpTestSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func TestHelpTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(HelpTestSuite))
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestPrepare() {
|
||||
ctrl := gomock.NewController(suite.T())
|
||||
defer ctrl.Finish()
|
||||
|
||||
mCmd := NewMockcmd(ctrl)
|
||||
originalCommand := command
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
assert.Equal(t, helmBin, path)
|
||||
assert.Equal(t, []string{"help"}, args)
|
||||
assert.Equal(suite.T(), helmBin, path)
|
||||
assert.Equal(suite.T(), []string{"help"}, args)
|
||||
return mCmd
|
||||
}
|
||||
defer func() { command = originalCommand }()
|
||||
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
|
||||
mCmd.EXPECT().
|
||||
Stdout(gomock.Any())
|
||||
Stdout(&stdout)
|
||||
mCmd.EXPECT().
|
||||
Stderr(gomock.Any())
|
||||
Stderr(&stderr)
|
||||
mCmd.EXPECT().
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
h := NewHelp()
|
||||
h.Run()
|
||||
cfg := Config{
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
h := Help{}
|
||||
err := h.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
h.Execute()
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestPrepareDebugFlag() {
|
||||
help := Help{}
|
||||
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
cfg := Config{
|
||||
Debug: true,
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
help.Prepare(cfg)
|
||||
|
||||
want := fmt.Sprintf("Generated command: '%s --debug help'\n", helmBin)
|
||||
suite.Equal(want, stderr.String())
|
||||
suite.Equal("", stdout.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user