diff --git a/option.go b/option.go index 643a111..4ceac71 100644 --- a/option.go +++ b/option.go @@ -292,15 +292,7 @@ func (optSet *OptionSet) ParseEnv(vs []EnvVar) error { // because the agent lacked the environment variables to authenticate with Git. envVal, ok = envs[`HOMEBREW_`+opt.Env] } - // 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. - // - // TODO: We should remove this hack in May 2023, when deployments - // have had months to migrate to the new behavior. - if !ok || envVal == "" { + if !ok { continue } diff --git a/option_test.go b/option_test.go index 19aaef4..8b4d071 100644 --- a/option_test.go +++ b/option_test.go @@ -152,7 +152,35 @@ func TestOptionSet_ParseEnv(t *testing.T) { err = os.ParseEnv(serpent.ParseEnviron([]string{"CODER_WORKSPACE_NAME="}, "CODER_")) require.NoError(t, err) + // An explicitly empty environment variable should override the + // default value, allowing users to clear a default. + require.EqualValues(t, "", workspaceName) + require.Equal(t, serpent.ValueSourceEnv, os[0].ValueSource) + }) + + t.Run("EmptyValueUnset", func(t *testing.T) { + t.Parallel() + + var workspaceName serpent.String + + os := serpent.OptionSet{ + serpent.Option{ + Name: "Workspace Name", + Value: &workspaceName, + Default: "defname", + Env: "WORKSPACE_NAME", + }, + } + + err := os.SetDefaults() + require.NoError(t, err) + + // An env var that is not present at all should preserve the + // default value. + err = os.ParseEnv(serpent.ParseEnviron([]string{}, "CODER_")) + require.NoError(t, err) require.EqualValues(t, "defname", workspaceName) + require.Equal(t, serpent.ValueSourceDefault, os[0].ValueSource) }) t.Run("StringSlice", func(t *testing.T) {