Brush all the lint off this code I wrote in a haze

This commit is contained in:
Erin Call
2019-12-09 10:52:41 -08:00
parent e3051ec72e
commit 8d66036252
11 changed files with 47 additions and 21 deletions

View File

@@ -5,9 +5,14 @@ import (
"strings"
)
// The Config struct captures the `settings` and `environment` blocks inthe application's drone
// config. Configuration in drone's `settings` block arrives as uppercase env vars matching the
// config key, prefixed with `PLUGIN_`. Config from the `environment` block is *not* prefixed; any
// keys that are likely to be in that block (i.e. things that use `from_secret` need an explicit
// `envconfig:` tag so that envconfig will look for a non-prefixed env var.
type Config struct {
// Configuration for drone-helm itself
Command HelmCommand `envconfig:"HELM_COMMAND"` // Helm command to run
Command helmCommand `envconfig:"HELM_COMMAND"` // Helm command to run
DroneEvent string `envconfig:"DRONE_BUILD_EVENT"` // Drone event that invoked this plugin.
UpdateDependencies bool `split_words:"true"` // call `helm dependency update` before the main command
Repos []string `envconfig:"HELM_REPOS"` // call `helm repo add` before the main command
@@ -37,14 +42,14 @@ type Config struct {
Force bool `` //
}
type HelmCommand string
type helmCommand string
// HelmCommand.Decode checks the given value against the list of known commands and generates a helpful error if the command is unknown.
func (cmd *HelmCommand) Decode(value string) error {
// helmCommand.Decode checks the given value against the list of known commands and generates a helpful error if the command is unknown.
func (cmd *helmCommand) Decode(value string) error {
known := []string{"upgrade", "delete", "lint", "help"}
for _, c := range known {
if value == c {
*cmd = HelmCommand(value)
*cmd = helmCommand(value)
return nil
}
}
@@ -53,6 +58,6 @@ func (cmd *HelmCommand) Decode(value string) error {
return nil
}
known[len(known)-1] = fmt.Sprintf("or %s", known[len(known)-1])
return fmt.Errorf("Unknown command '%s'. If specified, command must be %s.",
return fmt.Errorf("unknown command '%s'. If specified, command must be %s",
value, strings.Join(known, ", "))
}

View File

@@ -14,7 +14,7 @@ func TestConfigTestSuite(t *testing.T) {
}
func (suite *ConfigTestSuite) TestHelmCommandDecodeSuccess() {
cmd := HelmCommand("")
cmd := helmCommand("")
err := cmd.Decode("upgrade")
suite.Require().Nil(err)
@@ -22,7 +22,7 @@ func (suite *ConfigTestSuite) TestHelmCommandDecodeSuccess() {
}
func (suite *ConfigTestSuite) TestHelmCommandDecodeFailure() {
cmd := HelmCommand("")
cmd := helmCommand("")
err := cmd.Decode("execute order 66")
suite.EqualError(err, "Unknown command 'execute order 66'. If specified, command must be upgrade, delete, lint, or help.")
suite.EqualError(err, "unknown command 'execute order 66'. If specified, command must be upgrade, delete, lint, or help")
}

View File

@@ -5,14 +5,17 @@ import (
"github.com/pelotech/drone-helm3/internal/run"
)
// A Step is one step in the plan.
type Step interface {
Run() error
}
// A Plan is a series of steps to perform.
type Plan struct {
steps []Step
}
// NewPlan makes a plan for running a helm operation.
func NewPlan(cfg Config) (*Plan, error) {
p := Plan{}
switch cfg.Command {
@@ -44,6 +47,7 @@ func NewPlan(cfg Config) (*Plan, error) {
return &p, nil
}
// Execute runs each step in the plan, aborting and reporting on error
func (p *Plan) Execute() error {
for _, step := range p.steps {
if err := step.Run(); err != nil {