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 {
|
||||
steps := make([]Step, 0)
|
||||
|
||||
steps = append(steps, &run.InitKube{
|
||||
SkipTLSVerify: cfg.SkipTLSVerify,
|
||||
Certificate: cfg.Certificate,
|
||||
APIServer: cfg.APIServer,
|
||||
ServiceAccount: cfg.ServiceAccount,
|
||||
Token: cfg.KubeToken,
|
||||
TemplateFile: kubeConfigTemplate,
|
||||
})
|
||||
steps := initKube(cfg)
|
||||
|
||||
steps = append(steps, &run.Upgrade{
|
||||
Chart: cfg.Chart,
|
||||
|
@ -119,6 +110,21 @@ var upgrade = 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{
|
||||
&run.InitKube{
|
||||
SkipTLSVerify: cfg.SkipTLSVerify,
|
||||
|
@ -128,14 +134,5 @@ var del = func(cfg Config) []Step {
|
|||
Token: cfg.KubeToken,
|
||||
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() {
|
||||
cfg := Config{
|
||||
KubeToken: "cXVlZXIgY2hhcmFjdGVyCg==",
|
||||
SkipTLSVerify: true,
|
||||
Certificate: "b2Ygd29rZW5lc3MK",
|
||||
APIServer: "123.456.78.9",
|
||||
ServiceAccount: "helmet",
|
||||
ChartVersion: "seventeen",
|
||||
DryRun: true,
|
||||
Wait: true,
|
||||
ReuseValues: true,
|
||||
Timeout: "go sit in the corner",
|
||||
Chart: "billboard_top_100",
|
||||
Release: "post_malone_circles",
|
||||
Force: true,
|
||||
ChartVersion: "seventeen",
|
||||
DryRun: true,
|
||||
Wait: true,
|
||||
ReuseValues: true,
|
||||
Timeout: "go sit in the corner",
|
||||
Chart: "billboard_top_100",
|
||||
Release: "post_malone_circles",
|
||||
Force: true,
|
||||
}
|
||||
|
||||
steps := upgrade(cfg)
|
||||
|
||||
suite.Equal(2, len(steps))
|
||||
|
||||
suite.Require().Equal(2, len(steps), "upgrade should return 2 steps")
|
||||
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])
|
||||
upgrade, _ := steps[1].(*run.Upgrade)
|
||||
|
||||
expected = &run.Upgrade{
|
||||
expected := &run.Upgrade{
|
||||
Chart: cfg.Chart,
|
||||
Release: cfg.Release,
|
||||
ChartVersion: cfg.ChartVersion,
|
||||
|
@ -174,6 +155,31 @@ func (suite *PlanTestSuite) TestDel() {
|
|||
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() {
|
||||
cfg := Config{
|
||||
Command: "upgrade",
|
||||
|
|
Loading…
Reference in a new issue