Instantiate a Delete when appropriate [#4]

"delete" would be a more natural name for the instantiation function,
but that's a reserved word in golang.
This commit is contained in:
Erin Call 2019-12-18 16:58:31 -08:00
parent a21d6ad61f
commit f398ee5724
No known key found for this signature in database
GPG key ID: 4071FF6C15B8DAD1
2 changed files with 73 additions and 1 deletions

View file

@ -60,7 +60,7 @@ func determineSteps(cfg Config) *func(Config) []Step {
case "upgrade":
return &upgrade
case "delete":
panic("not implemented")
return &del
case "lint":
panic("not implemented")
case "help":
@ -69,6 +69,8 @@ func determineSteps(cfg Config) *func(Config) []Step {
switch cfg.DroneEvent {
case "push", "tag", "deployment", "pull_request", "promote", "rollback":
return &upgrade
case "delete":
return &del
default:
panic("not implemented")
}
@ -116,6 +118,23 @@ var upgrade = func(cfg Config) []Step {
return steps
}
var del = func(cfg Config) []Step {
return []Step{
&run.InitKube{
SkipTLSVerify: cfg.SkipTLSVerify,
Certificate: cfg.Certificate,
APIServer: cfg.APIServer,
ServiceAccount: cfg.ServiceAccount,
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}

View file

@ -137,6 +137,43 @@ func (suite *PlanTestSuite) TestUpgrade() {
suite.Equal(expected, upgrade)
}
func (suite *PlanTestSuite) TestDel() {
cfg := Config{
KubeToken: "b2YgbXkgYWZmZWN0aW9u",
SkipTLSVerify: true,
Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw",
APIServer: "98.765.43.21",
ServiceAccount: "greathelm",
DryRun: true,
Timeout: "think about what you did",
Release: "jetta_id_love_to_change_the_world",
}
steps := del(cfg)
suite.Require().Equal(2, len(steps), "del should return 2 steps")
suite.Require().IsType(&run.InitKube{}, steps[0])
init, _ := steps[0].(*run.InitKube)
var expected Step = &run.InitKube{
SkipTLSVerify: true,
Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw",
APIServer: "98.765.43.21",
ServiceAccount: "greathelm",
Token: "b2YgbXkgYWZmZWN0aW9u",
TemplateFile: kubeConfigTemplate,
}
suite.Equal(expected, init)
suite.Require().IsType(&run.Delete{}, steps[1])
actual, _ := steps[1].(*run.Delete)
expected = &run.Delete{
Release: "jetta_id_love_to_change_the_world",
DryRun: true,
}
suite.Equal(expected, actual)
}
func (suite *PlanTestSuite) TestDeterminePlanUpgradeCommand() {
cfg := Config{
Command: "upgrade",
@ -156,6 +193,22 @@ func (suite *PlanTestSuite) TestDeterminePlanUpgradeFromDroneEvent() {
}
}
func (suite *PlanTestSuite) TestDeterminePlanDeleteCommand() {
cfg := Config{
Command: "delete",
}
stepsMaker := determineSteps(cfg)
suite.Same(&del, stepsMaker)
}
func (suite *PlanTestSuite) TestDeterminePlanDeleteFromDroneEvent() {
cfg := Config{
DroneEvent: "delete",
}
stepsMaker := determineSteps(cfg)
suite.Same(&del, stepsMaker)
}
func (suite *PlanTestSuite) TestDeterminePlanHelpCommand() {
cfg := Config{
Command: "help",