Initialize run.Configs in the NewSTEP functions [#67]
This fixes the run package's leaky abstraction; other packages no longer need to know or care that run.Config even exists. Note that since the various Steps now depend on having a non-nil pointer to a run.Config, it's unsafe (or at least risky) to initialize them directly. They should be created with their NewSTEPNAME functions. All their fields are now private, to reflect this.
This commit is contained in:
@@ -24,7 +24,7 @@ func (suite *HelpTestSuite) TestNewHelp() {
|
||||
}
|
||||
help := NewHelp(cfg)
|
||||
suite.Require().NotNil(help)
|
||||
suite.Equal("everybody dance NOW!!", help.HelmCommand)
|
||||
suite.Equal("everybody dance NOW!!", help.helmCommand)
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestPrepare() {
|
||||
@@ -49,13 +49,13 @@ func (suite *HelpTestSuite) TestPrepare() {
|
||||
mCmd.EXPECT().
|
||||
Stderr(&stderr)
|
||||
|
||||
cfg := Config{
|
||||
cfg := env.Config{
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
h := Help{}
|
||||
err := h.Prepare(cfg)
|
||||
h := NewHelp(cfg)
|
||||
err := h.Prepare()
|
||||
suite.NoError(err)
|
||||
}
|
||||
|
||||
@@ -63,38 +63,30 @@ 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)
|
||||
|
||||
help := Help{
|
||||
HelmCommand: "help",
|
||||
cmd: mCmd,
|
||||
}
|
||||
help := NewHelp(env.Config{Command: "help"})
|
||||
help.cmd = mCmd
|
||||
suite.NoError(help.Execute())
|
||||
|
||||
help.HelmCommand = "get down on friday"
|
||||
help.helmCommand = "get down on friday"
|
||||
suite.EqualError(help.Execute(), "unknown command 'get down on friday'")
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestPrepareDebugFlag() {
|
||||
help := Help{}
|
||||
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
cfg := Config{
|
||||
cfg := env.Config{
|
||||
Debug: true,
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
help.Prepare(cfg)
|
||||
help := NewHelp(cfg)
|
||||
help.Prepare()
|
||||
|
||||
want := fmt.Sprintf("Generated command: '%s --debug help'\n", helmBin)
|
||||
suite.Equal(want, stderr.String())
|
||||
|
||||
Reference in New Issue
Block a user