Remove the tiny helper functions from plan.go [#67]

Now that InitKube, AddRepo, and UpdateDependencies are initialized with
NewSTEPNAME functions, the helper functions in plan.go are
unnecessary--they do too little to be a useful abstraction, and they
aren't complex or frequently-used enough to be worth extracting.
This commit is contained in:
Erin Call 2020-01-16 13:57:28 -08:00
parent 588c7cb9f7
commit 21b9d32329
No known key found for this signature in database
GPG key ID: 4071FF6C15B8DAD1
2 changed files with 14 additions and 55 deletions

View file

@ -93,10 +93,13 @@ func (p *Plan) Execute() error {
}
var upgrade = func(cfg env.Config) []Step {
steps := initKube(cfg)
steps = append(steps, addRepos(cfg)...)
var steps []Step
steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile))
for _, repo := range cfg.AddRepos {
steps = append(steps, run.NewAddRepo(repo))
}
if cfg.UpdateDependencies {
steps = append(steps, depUpdate(cfg)...)
steps = append(steps, run.NewDepUpdate(cfg))
}
steps = append(steps, run.NewUpgrade(cfg))
@ -104,9 +107,10 @@ var upgrade = func(cfg env.Config) []Step {
}
var uninstall = func(cfg env.Config) []Step {
steps := initKube(cfg)
var steps []Step
steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile))
if cfg.UpdateDependencies {
steps = append(steps, depUpdate(cfg)...)
steps = append(steps, run.NewDepUpdate(cfg))
}
steps = append(steps, run.NewUninstall(cfg))
@ -114,9 +118,12 @@ var uninstall = func(cfg env.Config) []Step {
}
var lint = func(cfg env.Config) []Step {
steps := addRepos(cfg)
var steps []Step
for _, repo := range cfg.AddRepos {
steps = append(steps, run.NewAddRepo(repo))
}
if cfg.UpdateDependencies {
steps = append(steps, depUpdate(cfg)...)
steps = append(steps, run.NewDepUpdate(cfg))
}
steps = append(steps, run.NewLint(cfg))
return steps
@ -125,20 +132,3 @@ var lint = func(cfg env.Config) []Step {
var help = func(cfg env.Config) []Step {
return []Step{run.NewHelp(cfg)}
}
func initKube(cfg env.Config) []Step {
return []Step{run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile)}
}
func addRepos(cfg env.Config) []Step {
steps := make([]Step, 0)
for _, repo := range cfg.AddRepos {
steps = append(steps, run.NewAddRepo(repo))
}
return steps
}
func depUpdate(cfg env.Config) []Step {
return []Step{run.NewDepUpdate(cfg)}
}

View file

@ -175,37 +175,6 @@ func (suite *PlanTestSuite) TestUninstallWithUpdateDependencies() {
suite.IsType(&run.DepUpdate{}, steps[1])
}
func (suite *PlanTestSuite) TestInitKube() {
cfg := env.Config{}
steps := initKube(cfg)
suite.Require().Equal(1, len(steps), "initKube should return one step")
suite.IsType(&run.InitKube{}, steps[0])
}
func (suite *PlanTestSuite) TestDepUpdate() {
cfg := env.Config{
UpdateDependencies: true,
}
steps := depUpdate(cfg)
suite.Require().Equal(1, len(steps), "depUpdate should return one step")
suite.IsType(&run.DepUpdate{}, steps[0])
}
func (suite *PlanTestSuite) TestAddRepos() {
cfg := env.Config{
AddRepos: []string{
"first=https://add.repos/one",
"second=https://add.repos/two",
},
}
steps := addRepos(cfg)
suite.Require().Equal(2, len(steps), "addRepos should add one step per repo")
suite.IsType(&run.AddRepo{}, steps[0])
suite.IsType(&run.AddRepo{}, steps[1])
}
func (suite *PlanTestSuite) TestLint() {
steps := lint(env.Config{})
suite.Require().Equal(1, len(steps))