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:
parent
588c7cb9f7
commit
21b9d32329
|
@ -93,10 +93,13 @@ func (p *Plan) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var upgrade = func(cfg env.Config) []Step {
|
var upgrade = func(cfg env.Config) []Step {
|
||||||
steps := initKube(cfg)
|
var steps []Step
|
||||||
steps = append(steps, addRepos(cfg)...)
|
steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile))
|
||||||
|
for _, repo := range cfg.AddRepos {
|
||||||
|
steps = append(steps, run.NewAddRepo(repo))
|
||||||
|
}
|
||||||
if cfg.UpdateDependencies {
|
if cfg.UpdateDependencies {
|
||||||
steps = append(steps, depUpdate(cfg)...)
|
steps = append(steps, run.NewDepUpdate(cfg))
|
||||||
}
|
}
|
||||||
steps = append(steps, run.NewUpgrade(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 {
|
var uninstall = func(cfg env.Config) []Step {
|
||||||
steps := initKube(cfg)
|
var steps []Step
|
||||||
|
steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile))
|
||||||
if cfg.UpdateDependencies {
|
if cfg.UpdateDependencies {
|
||||||
steps = append(steps, depUpdate(cfg)...)
|
steps = append(steps, run.NewDepUpdate(cfg))
|
||||||
}
|
}
|
||||||
steps = append(steps, run.NewUninstall(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 {
|
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 {
|
if cfg.UpdateDependencies {
|
||||||
steps = append(steps, depUpdate(cfg)...)
|
steps = append(steps, run.NewDepUpdate(cfg))
|
||||||
}
|
}
|
||||||
steps = append(steps, run.NewLint(cfg))
|
steps = append(steps, run.NewLint(cfg))
|
||||||
return steps
|
return steps
|
||||||
|
@ -125,20 +132,3 @@ var lint = func(cfg env.Config) []Step {
|
||||||
var help = func(cfg env.Config) []Step {
|
var help = func(cfg env.Config) []Step {
|
||||||
return []Step{run.NewHelp(cfg)}
|
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)}
|
|
||||||
}
|
|
||||||
|
|
|
@ -175,37 +175,6 @@ func (suite *PlanTestSuite) TestUninstallWithUpdateDependencies() {
|
||||||
suite.IsType(&run.DepUpdate{}, steps[1])
|
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() {
|
func (suite *PlanTestSuite) TestLint() {
|
||||||
steps := lint(env.Config{})
|
steps := lint(env.Config{})
|
||||||
suite.Require().Equal(1, len(steps))
|
suite.Require().Equal(1, len(steps))
|
||||||
|
|
Loading…
Reference in a new issue