Extract Plan's InitKube creation [#4]
It's `func initKube` rather than `var initKube = func` because initKube is not meant to be returned by determineSteps.
This commit is contained in:
parent
f398ee5724
commit
5de156f823
|
@ -93,16 +93,7 @@ func (p *Plan) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var upgrade = func(cfg Config) []Step {
|
var upgrade = func(cfg Config) []Step {
|
||||||
steps := make([]Step, 0)
|
steps := initKube(cfg)
|
||||||
|
|
||||||
steps = append(steps, &run.InitKube{
|
|
||||||
SkipTLSVerify: cfg.SkipTLSVerify,
|
|
||||||
Certificate: cfg.Certificate,
|
|
||||||
APIServer: cfg.APIServer,
|
|
||||||
ServiceAccount: cfg.ServiceAccount,
|
|
||||||
Token: cfg.KubeToken,
|
|
||||||
TemplateFile: kubeConfigTemplate,
|
|
||||||
})
|
|
||||||
|
|
||||||
steps = append(steps, &run.Upgrade{
|
steps = append(steps, &run.Upgrade{
|
||||||
Chart: cfg.Chart,
|
Chart: cfg.Chart,
|
||||||
|
@ -119,6 +110,21 @@ var upgrade = func(cfg Config) []Step {
|
||||||
}
|
}
|
||||||
|
|
||||||
var del = func(cfg Config) []Step {
|
var del = func(cfg Config) []Step {
|
||||||
|
steps := initKube(cfg)
|
||||||
|
steps = append(steps, &run.Delete{
|
||||||
|
Release: cfg.Release,
|
||||||
|
DryRun: cfg.DryRun,
|
||||||
|
})
|
||||||
|
|
||||||
|
return steps
|
||||||
|
}
|
||||||
|
|
||||||
|
var help = func(cfg Config) []Step {
|
||||||
|
help := &run.Help{}
|
||||||
|
return []Step{help}
|
||||||
|
}
|
||||||
|
|
||||||
|
func initKube(cfg Config) []Step {
|
||||||
return []Step{
|
return []Step{
|
||||||
&run.InitKube{
|
&run.InitKube{
|
||||||
SkipTLSVerify: cfg.SkipTLSVerify,
|
SkipTLSVerify: cfg.SkipTLSVerify,
|
||||||
|
@ -128,14 +134,5 @@ var del = func(cfg Config) []Step {
|
||||||
Token: cfg.KubeToken,
|
Token: cfg.KubeToken,
|
||||||
TemplateFile: kubeConfigTemplate,
|
TemplateFile: kubeConfigTemplate,
|
||||||
},
|
},
|
||||||
&run.Delete{
|
|
||||||
Release: cfg.Release,
|
|
||||||
DryRun: cfg.DryRun,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var help = func(cfg Config) []Step {
|
|
||||||
help := &run.Help{}
|
|
||||||
return []Step{help}
|
|
||||||
}
|
|
||||||
|
|
|
@ -87,43 +87,24 @@ func (suite *PlanTestSuite) TestNewPlanAbortsOnError() {
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestUpgrade() {
|
func (suite *PlanTestSuite) TestUpgrade() {
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
KubeToken: "cXVlZXIgY2hhcmFjdGVyCg==",
|
ChartVersion: "seventeen",
|
||||||
SkipTLSVerify: true,
|
DryRun: true,
|
||||||
Certificate: "b2Ygd29rZW5lc3MK",
|
Wait: true,
|
||||||
APIServer: "123.456.78.9",
|
ReuseValues: true,
|
||||||
ServiceAccount: "helmet",
|
Timeout: "go sit in the corner",
|
||||||
ChartVersion: "seventeen",
|
Chart: "billboard_top_100",
|
||||||
DryRun: true,
|
Release: "post_malone_circles",
|
||||||
Wait: true,
|
Force: true,
|
||||||
ReuseValues: true,
|
|
||||||
Timeout: "go sit in the corner",
|
|
||||||
Chart: "billboard_top_100",
|
|
||||||
Release: "post_malone_circles",
|
|
||||||
Force: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
steps := upgrade(cfg)
|
steps := upgrade(cfg)
|
||||||
|
suite.Require().Equal(2, len(steps), "upgrade should return 2 steps")
|
||||||
suite.Equal(2, len(steps))
|
|
||||||
|
|
||||||
suite.Require().IsType(&run.InitKube{}, steps[0])
|
suite.Require().IsType(&run.InitKube{}, steps[0])
|
||||||
init, _ := steps[0].(*run.InitKube)
|
|
||||||
|
|
||||||
var expected Step = &run.InitKube{
|
|
||||||
SkipTLSVerify: cfg.SkipTLSVerify,
|
|
||||||
Certificate: cfg.Certificate,
|
|
||||||
APIServer: cfg.APIServer,
|
|
||||||
ServiceAccount: cfg.ServiceAccount,
|
|
||||||
Token: cfg.KubeToken,
|
|
||||||
TemplateFile: kubeConfigTemplate,
|
|
||||||
}
|
|
||||||
|
|
||||||
suite.Equal(expected, init)
|
|
||||||
|
|
||||||
suite.Require().IsType(&run.Upgrade{}, steps[1])
|
suite.Require().IsType(&run.Upgrade{}, steps[1])
|
||||||
upgrade, _ := steps[1].(*run.Upgrade)
|
upgrade, _ := steps[1].(*run.Upgrade)
|
||||||
|
|
||||||
expected = &run.Upgrade{
|
expected := &run.Upgrade{
|
||||||
Chart: cfg.Chart,
|
Chart: cfg.Chart,
|
||||||
Release: cfg.Release,
|
Release: cfg.Release,
|
||||||
ChartVersion: cfg.ChartVersion,
|
ChartVersion: cfg.ChartVersion,
|
||||||
|
@ -174,6 +155,31 @@ func (suite *PlanTestSuite) TestDel() {
|
||||||
suite.Equal(expected, actual)
|
suite.Equal(expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *PlanTestSuite) TestInitKube() {
|
||||||
|
cfg := Config{
|
||||||
|
KubeToken: "cXVlZXIgY2hhcmFjdGVyCg==",
|
||||||
|
SkipTLSVerify: true,
|
||||||
|
Certificate: "b2Ygd29rZW5lc3MK",
|
||||||
|
APIServer: "123.456.78.9",
|
||||||
|
ServiceAccount: "helmet",
|
||||||
|
}
|
||||||
|
|
||||||
|
steps := initKube(cfg)
|
||||||
|
suite.Require().Equal(1, len(steps), "initKube should return one step")
|
||||||
|
suite.Require().IsType(&run.InitKube{}, steps[0])
|
||||||
|
init, _ := steps[0].(*run.InitKube)
|
||||||
|
|
||||||
|
expected := &run.InitKube{
|
||||||
|
SkipTLSVerify: true,
|
||||||
|
Certificate: "b2Ygd29rZW5lc3MK",
|
||||||
|
APIServer: "123.456.78.9",
|
||||||
|
ServiceAccount: "helmet",
|
||||||
|
Token: "cXVlZXIgY2hhcmFjdGVyCg==",
|
||||||
|
TemplateFile: kubeConfigTemplate,
|
||||||
|
}
|
||||||
|
suite.Equal(expected, init)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestDeterminePlanUpgradeCommand() {
|
func (suite *PlanTestSuite) TestDeterminePlanUpgradeCommand() {
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
Command: "upgrade",
|
Command: "upgrade",
|
||||||
|
|
Loading…
Reference in a new issue