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:
@@ -43,19 +43,19 @@ func (suite *UninstallTestSuite) TestNewUninstall() {
|
||||
KeepHistory: true,
|
||||
}
|
||||
u := NewUninstall(cfg)
|
||||
suite.Equal(&Uninstall{
|
||||
Release: "jetta_id_love_to_change_the_world",
|
||||
DryRun: true,
|
||||
KeepHistory: true,
|
||||
}, u)
|
||||
suite.Equal("jetta_id_love_to_change_the_world", u.release)
|
||||
suite.Equal(true, u.dryRun)
|
||||
suite.Equal(true, u.keepHistory)
|
||||
suite.NotNil(u.config)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
u := Uninstall{
|
||||
cfg := env.Config{
|
||||
Release: "zayde_wølf_king",
|
||||
}
|
||||
u := NewUninstall(cfg)
|
||||
|
||||
actual := []string{}
|
||||
command = func(path string, args ...string) cmd {
|
||||
@@ -73,8 +73,7 @@ func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
cfg := Config{}
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
suite.NoError(u.Prepare())
|
||||
expected := []string{"uninstall", "zayde_wølf_king"}
|
||||
suite.Equal(expected, actual)
|
||||
|
||||
@@ -82,60 +81,58 @@ func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareDryRunFlag() {
|
||||
u := Uninstall{
|
||||
cfg := env.Config{
|
||||
Release: "firefox_ak_wildfire",
|
||||
DryRun: true,
|
||||
}
|
||||
cfg := Config{}
|
||||
u := NewUninstall(cfg)
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
suite.NoError(u.Prepare())
|
||||
expected := []string{"uninstall", "--dry-run", "firefox_ak_wildfire"}
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareKeepHistoryFlag() {
|
||||
u := Uninstall{
|
||||
cfg := env.Config{
|
||||
Release: "perturbator_sentient",
|
||||
KeepHistory: true,
|
||||
}
|
||||
cfg := Config{}
|
||||
u := NewUninstall(cfg)
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
suite.NoError(u.Prepare())
|
||||
expected := []string{"uninstall", "--keep-history", "perturbator_sentient"}
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareNamespaceFlag() {
|
||||
u := Uninstall{
|
||||
Release: "carly_simon_run_away_with_me",
|
||||
}
|
||||
cfg := Config{
|
||||
cfg := env.Config{
|
||||
Release: "carly_simon_run_away_with_me",
|
||||
Namespace: "emotion",
|
||||
}
|
||||
u := NewUninstall(cfg)
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
suite.NoError(u.Prepare())
|
||||
expected := []string{"--namespace", "emotion", "uninstall", "carly_simon_run_away_with_me"}
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareDebugFlag() {
|
||||
u := Uninstall{
|
||||
Release: "just_a_band_huff_and_puff",
|
||||
}
|
||||
stderr := strings.Builder{}
|
||||
cfg := Config{
|
||||
Debug: true,
|
||||
Stderr: &stderr,
|
||||
cfg := env.Config{
|
||||
Release: "just_a_band_huff_and_puff",
|
||||
Debug: true,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
u := NewUninstall(cfg)
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.mockCmd.EXPECT().
|
||||
@@ -148,7 +145,7 @@ func (suite *UninstallTestSuite) TestPrepareDebugFlag() {
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(&stderr).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
suite.NoError(u.Prepare())
|
||||
suite.Equal(fmt.Sprintf("Generated command: '%s --debug "+
|
||||
"uninstall just_a_band_huff_and_puff'\n", helmBin), stderr.String())
|
||||
}
|
||||
@@ -158,7 +155,7 @@ func (suite *UninstallTestSuite) TestPrepareRequiresRelease() {
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
u := Uninstall{}
|
||||
err := u.Prepare(Config{})
|
||||
u := NewUninstall(env.Config{})
|
||||
err := u.Prepare()
|
||||
suite.EqualError(err, "release is required", "Uninstall.Release should be mandatory")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user