Process non-prefixed forms of all config settings [#9]

Trying to guess in advance which part of the config a user will put in
the `settings` section and which they'll put in `environment` is a
fool's errand. Just let everything go in either place.

The ServiceAccount field only had an `envconfig` tag (as opposed to
`split_words`) because that triggered envconfig to look for the non-
prefixed form. Now that we're finding non-prefixed forms of everything,
we can use the clearer/more concise tag.

Note that TestPopulateWithConflictingVariables isn't meant to say
"here's what behavior we *want*" so much as "here's what the behavior
*is*." I don't think one thing is any better than the other, but we
should know which one we're getting.
This commit is contained in:
Erin Call
2019-12-23 15:31:40 -08:00
parent c4c136b021
commit e2f53f3b08
2 changed files with 42 additions and 3 deletions

View File

@@ -18,6 +18,10 @@ func TestConfigTestSuite(t *testing.T) {
}
func (suite *ConfigTestSuite) TestPopulateWithPluginPrefix() {
suite.unsetenv("HELM_COMMAND")
suite.unsetenv("UPDATE_DEPENDENCIES")
suite.unsetenv("DEBUG")
suite.setenv("PLUGIN_HELM_COMMAND", "execute order 66")
suite.setenv("PLUGIN_UPDATE_DEPENDENCIES", "true")
suite.setenv("PLUGIN_DEBUG", "true")
@@ -30,6 +34,33 @@ func (suite *ConfigTestSuite) TestPopulateWithPluginPrefix() {
suite.True(cfg.Debug)
}
func (suite *ConfigTestSuite) TestPopulateWithNoPrefix() {
suite.unsetenv("PLUGIN_HELM_COMMAND")
suite.unsetenv("PLUGIN_UPDATE_DEPENDENCIES")
suite.unsetenv("PLUGIN_DEBUG")
suite.setenv("HELM_COMMAND", "execute order 66")
suite.setenv("UPDATE_DEPENDENCIES", "true")
suite.setenv("DEBUG", "true")
cfg := Config{}
cfg.Populate()
suite.Equal("execute order 66", cfg.Command)
suite.True(cfg.UpdateDependencies)
suite.True(cfg.Debug)
}
func (suite *ConfigTestSuite) TestPopulateWithConflictingVariables() {
suite.setenv("PLUGIN_HELM_COMMAND", "execute order 66")
suite.setenv("HELM_COMMAND", "defend the jedi")
cfg := Config{}
cfg.Populate()
suite.Equal("defend the jedi", cfg.Command)
}
func (suite *ConfigTestSuite) setenv(key, val string) {
orig, ok := os.LookupEnv(key)
if ok {