Use a plain string for helm.Config.Command [#9]

I'm leaving the no-op test file in place because my next step is to add
new behavior that will require testing.
This commit is contained in:
Erin Call 2019-12-23 14:06:05 -08:00
parent ae9cb59a1f
commit ef4db923cd
No known key found for this signature in database
GPG key ID: 4071FF6C15B8DAD1
2 changed files with 24 additions and 61 deletions

View file

@ -1,9 +1,6 @@
package helm package helm
import ( import ()
"fmt"
"strings"
)
// The Config struct captures the `settings` and `environment` blocks in the application's drone // The Config struct captures the `settings` and `environment` blocks in the application's drone
// config. Configuration in drone's `settings` block arrives as uppercase env vars matching the // config. Configuration in drone's `settings` block arrives as uppercase env vars matching the
@ -12,7 +9,7 @@ import (
// `envconfig:` tag so that envconfig will look for a non-prefixed env var. // `envconfig:` tag so that envconfig will look for a non-prefixed env var.
type Config struct { type Config struct {
// Configuration for drone-helm itself // Configuration for drone-helm itself
Command helmCommand `envconfig:"HELM_COMMAND"` // Helm command to run Command string `envconfig:"HELM_COMMAND"` // Helm command to run
DroneEvent string `envconfig:"DRONE_BUILD_EVENT"` // Drone event that invoked this plugin. 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 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 Repos []string `envconfig:"HELM_REPOS"` // Call `helm repo add` before the main command
@ -36,23 +33,3 @@ type Config struct {
Release string `` // Release argument to use in applicable helm commands Release string `` // Release argument to use in applicable helm commands
Force bool `` // Pass --force to applicable helm commands Force bool `` // Pass --force to applicable helm commands
} }
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 {
known := []string{"upgrade", "delete", "lint", "help"}
for _, c := range known {
if value == c {
*cmd = helmCommand(value)
return nil
}
}
if value == "" {
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",
value, strings.Join(known, ", "))
}

View file

@ -12,17 +12,3 @@ type ConfigTestSuite struct {
func TestConfigTestSuite(t *testing.T) { func TestConfigTestSuite(t *testing.T) {
suite.Run(t, new(ConfigTestSuite)) suite.Run(t, new(ConfigTestSuite))
} }
func (suite *ConfigTestSuite) TestHelmCommandDecodeSuccess() {
cmd := helmCommand("")
err := cmd.Decode("upgrade")
suite.Require().Nil(err)
suite.EqualValues(cmd, "upgrade")
}
func (suite *ConfigTestSuite) TestHelmCommandDecodeFailure() {
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")
}