Brush all the lint off this code I wrote in a haze
This commit is contained in:
@@ -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, ", "))
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const HELM_BIN = "/usr/bin/helm"
|
||||
const helmBin = "/usr/bin/helm"
|
||||
|
||||
// The cmd interface provides a generic form of exec.Cmd so that it can be mocked out in tests.
|
||||
type cmd interface {
|
||||
@@ -43,7 +43,7 @@ type execCmd struct {
|
||||
*exec.Cmd
|
||||
}
|
||||
|
||||
var Command = func(path string, args ...string) cmd {
|
||||
var command = func(path string, args ...string) cmd {
|
||||
return &execCmd{
|
||||
Cmd: exec.Command(path, args...),
|
||||
}
|
||||
|
||||
@@ -4,18 +4,21 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// Help is a step in a helm Plan that calls `helm help`.
|
||||
type Help struct {
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// Run launches the command.
|
||||
func (h *Help) Run() error {
|
||||
return h.cmd.Run()
|
||||
}
|
||||
|
||||
// NewHelp returns a new Help.
|
||||
func NewHelp() *Help {
|
||||
h := Help{}
|
||||
|
||||
h.cmd = Command(HELM_BIN, "help")
|
||||
h.cmd = command(helmBin, "help")
|
||||
h.cmd.Stdout(os.Stdout)
|
||||
h.cmd.Stderr(os.Stderr)
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ func TestHelp(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
|
||||
mCmd := NewMockcmd(ctrl)
|
||||
originalCommand := Command
|
||||
originalCommand := command
|
||||
|
||||
Command = func(path string, args ...string) cmd {
|
||||
assert.Equal(t, HELM_BIN, path)
|
||||
command = func(path string, args ...string) cmd {
|
||||
assert.Equal(t, helmBin, path)
|
||||
assert.Equal(t, []string{"help"}, args)
|
||||
return mCmd
|
||||
}
|
||||
defer func() { Command = originalCommand }()
|
||||
defer func() { command = originalCommand }()
|
||||
|
||||
mCmd.EXPECT().
|
||||
Stdout(gomock.Any())
|
||||
|
||||
@@ -4,21 +4,24 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// Upgrade is a step in a helm Plan that calls `helm upgrade`.
|
||||
type Upgrade struct {
|
||||
Chart string
|
||||
Release string
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// Run launches the command.
|
||||
func (u *Upgrade) Run() error {
|
||||
return u.cmd.Run()
|
||||
}
|
||||
|
||||
// NewUpgrade creates a new Upgrade.
|
||||
func NewUpgrade(release, chart string) *Upgrade {
|
||||
u := Upgrade{
|
||||
Chart: chart,
|
||||
Release: release,
|
||||
cmd: Command(HELM_BIN, "upgrade", "--install", release, chart),
|
||||
cmd: command(helmBin, "upgrade", "--install", release, chart),
|
||||
}
|
||||
|
||||
u.cmd.Stdout(os.Stdout)
|
||||
|
||||
@@ -11,15 +11,15 @@ func TestNewUpgrade(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
|
||||
mCmd := NewMockcmd(ctrl)
|
||||
originalCommand := Command
|
||||
originalCommand := command
|
||||
|
||||
Command = func(path string, args ...string) cmd {
|
||||
assert.Equal(t, HELM_BIN, path)
|
||||
command = func(path string, args ...string) cmd {
|
||||
assert.Equal(t, helmBin, path)
|
||||
assert.Equal(t, []string{"upgrade", "--install", "jonas_brothers_only_human", "at40"}, args)
|
||||
|
||||
return mCmd
|
||||
}
|
||||
defer func() { Command = originalCommand }()
|
||||
defer func() { command = originalCommand }()
|
||||
|
||||
mCmd.EXPECT().
|
||||
Stdout(gomock.Any())
|
||||
|
||||
Reference in New Issue
Block a user