Fix snake_case env vars (#4267)

This commit is contained in:
qwerty287 2024-10-28 18:23:49 +02:00 committed by GitHub
parent 9a7623359e
commit bd933669ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -44,8 +44,9 @@ func ParamsToEnv(from map[string]any, to map[string]string, prefix string, upper
// sanitizeParamKey formats the environment variable key.
func sanitizeParamKey(prefix string, upper bool, k string) string {
r := strings.ReplaceAll(strings.ReplaceAll(k, ".", "_"), "-", "_")
r := k
if upper {
r = strings.ReplaceAll(strings.ReplaceAll(k, ".", "_"), "-", "_")
r = strings.ToUpper(r)
}
return prefix + r

View file

@ -110,8 +110,9 @@ func TestSanitizeParamKey(t *testing.T) {
assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry-run"))
assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry_Run"))
assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry.run"))
assert.EqualValues(t, "PLUGIN_dry_run", sanitizeParamKey("PLUGIN_", false, "dry-run"))
assert.EqualValues(t, "PLUGIN_dry-run", sanitizeParamKey("PLUGIN_", false, "dry-run"))
assert.EqualValues(t, "PLUGIN_dry_Run", sanitizeParamKey("PLUGIN_", false, "dry_Run"))
assert.EqualValues(t, "PLUGIN_dry.run", sanitizeParamKey("PLUGIN_", false, "dry.run"))
}
func TestYAMLToParamsToEnv(t *testing.T) {