diff --git a/internal/helm/plan.go b/internal/helm/plan.go index 3dc4ce2..e60389d 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -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} -} diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index b975504..6e293e2 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -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",