Merge branch 'master' into deprecation-warnings
This commit is contained in:
@@ -17,14 +17,13 @@ var (
|
||||
// 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 key, prefixed with `PLUGIN_`. Config from the `environment` block is uppercased, but does
|
||||
// not have the `PLUGIN_` prefix. It may, however, be prefixed with the value in `$PLUGIN_PREFIX`.
|
||||
// not have the `PLUGIN_` prefix.
|
||||
type Config struct {
|
||||
// Configuration for drone-helm itself
|
||||
Command string `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
|
||||
AddRepos []string `envconfig:"HELM_REPOS"` // Call `helm repo add` before the main command
|
||||
Prefix string `` // Prefix to use when looking up secret env vars
|
||||
Debug bool `` // Generate debug output and pass --debug to all helm commands
|
||||
Values string `` // Argument to pass to --set in applicable helm commands
|
||||
StringValues string `split_words:"true"` // Argument to pass to --set-string in applicable helm commands
|
||||
@@ -58,18 +57,10 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prefix := cfg.Prefix
|
||||
|
||||
if err := envconfig.Process("", &cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if prefix != "" {
|
||||
if err := envconfig.Process(cfg.Prefix, &cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if justNumbers.MatchString(cfg.Timeout) {
|
||||
cfg.Timeout = fmt.Sprintf("%ss", cfg.Timeout)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ func TestConfigTestSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithPluginPrefix() {
|
||||
suite.unsetenv("PLUGIN_PREFIX")
|
||||
suite.unsetenv("HELM_COMMAND")
|
||||
suite.unsetenv("UPDATE_DEPENDENCIES")
|
||||
suite.unsetenv("DEBUG")
|
||||
@@ -38,7 +37,6 @@ func (suite *ConfigTestSuite) TestNewConfigWithPluginPrefix() {
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithNoPrefix() {
|
||||
suite.unsetenv("PLUGIN_PREFIX")
|
||||
suite.unsetenv("PLUGIN_HELM_COMMAND")
|
||||
suite.unsetenv("PLUGIN_UPDATE_DEPENDENCIES")
|
||||
suite.unsetenv("PLUGIN_DEBUG")
|
||||
@@ -55,56 +53,14 @@ func (suite *ConfigTestSuite) TestNewConfigWithNoPrefix() {
|
||||
suite.True(cfg.Debug)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithConfigurablePrefix() {
|
||||
suite.unsetenv("API_SERVER")
|
||||
suite.unsetenv("PLUGIN_API_SERVER")
|
||||
|
||||
suite.setenv("PLUGIN_PREFIX", "prix_fixe")
|
||||
suite.setenv("PRIX_FIXE_API_SERVER", "your waiter this evening")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("prix_fixe", cfg.Prefix)
|
||||
suite.Equal("your waiter this evening", cfg.APIServer)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestPrefixSettingDoesNotAffectPluginPrefix() {
|
||||
suite.setenv("PLUGIN_PREFIX", "IXFREP")
|
||||
suite.setenv("PLUGIN_HELM_COMMAND", "wake me up")
|
||||
suite.setenv("IXFREP_PLUGIN_HELM_COMMAND", "send me to sleep inside")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("wake me up", cfg.Command)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestPrefixSettingMustHavePluginPrefix() {
|
||||
suite.unsetenv("PLUGIN_PREFIX")
|
||||
suite.setenv("PREFIX", "refpix")
|
||||
suite.setenv("HELM_COMMAND", "gimme more")
|
||||
suite.setenv("REFPIX_HELM_COMMAND", "gimme less")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("gimme more", cfg.Command)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithConflictingVariables() {
|
||||
suite.setenv("PLUGIN_HELM_COMMAND", "execute order 66")
|
||||
suite.setenv("HELM_COMMAND", "defend the jedi") // values from the `environment` block override those from `settings`
|
||||
|
||||
suite.setenv("PLUGIN_PREFIX", "prod")
|
||||
suite.setenv("TIMEOUT", "5m0s")
|
||||
suite.setenv("PROD_TIMEOUT", "2m30s") // values from prefixed env vars override those from non-prefixed ones
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("defend the jedi", cfg.Command)
|
||||
suite.Equal("2m30s", cfg.Timeout)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigInfersNumbersAreSeconds() {
|
||||
|
||||
Reference in New Issue
Block a user