mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: treat empty env as defaults (#6538)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user