fix: treat empty env as defaults (#6538)

This commit is contained in:
Ammar Bandukwala
2023-03-09 19:58:58 +00:00
committed by GitHub
parent 62a64d5a34
commit 4c2977050d
2 changed files with 28 additions and 1 deletions
+6 -1
View File
@@ -107,7 +107,12 @@ func (s *OptionSet) ParseEnv(globalPrefix string, environ []string) error {
}
envVal, ok := envs[opt.Env]
if !ok {
// Currently, empty values are treated as if the environment variable is
// unset. This behavior is technically not correct as there is now no
// way for a user to change a Default value to an empty string from
// the environment. Unfortunately, we have old configuration files
// that rely on the faulty behavior.
if !ok || envVal == "" {
continue
}
+22
View File
@@ -91,4 +91,26 @@ func TestOptionSet_ParseEnv(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, "foo", workspaceName)
})
t.Run("EmptyValue", func(t *testing.T) {
t.Parallel()
var workspaceName clibase.String
os := clibase.OptionSet{
clibase.Option{
Name: "Workspace Name",
Value: &workspaceName,
Default: "defname",
Env: "WORKSPACE_NAME",
},
}
err := os.SetDefaults()
require.NoError(t, err)
err = os.ParseEnv("CODER_", []string{"CODER_WORKSPACE_NAME="})
require.NoError(t, err)
require.EqualValues(t, "defname", workspaceName)
})
}