Commit 278a3314 authored by Cristian Maglie's avatar Cristian Maglie

Applied changes from code review

parent b279d4b3
......@@ -83,21 +83,19 @@ func (c *Map) InjectEnvVars(env []string, prefix string) []error {
envKeyToConfigKey := map[string]string{}
for _, k := range c.AllKeys() {
normalizedKey := prefix + strings.ToUpper(k)
normalizedKey = strings.Replace(normalizedKey, ".", "_", -1)
normalizedKey = strings.ReplaceAll(normalizedKey, ".", "_")
envKeyToConfigKey[normalizedKey] = k
}
for _, e := range env {
// Extract key and value from env
parts := strings.SplitN(e, "=", 2)
if len(parts) != 2 {
envKey, envValue, ok := strings.Cut(e, "=")
if !ok {
continue
}
envKey := strings.ToUpper(parts[0])
envValue := parts[1]
// Check if the configuration has a matching key
key, ok := envKeyToConfigKey[envKey]
key, ok := envKeyToConfigKey[strings.ToUpper(envKey)]
if !ok {
continue
}
......
......@@ -17,7 +17,6 @@ package configmap_test
import (
"encoding/json"
"fmt"
"testing"
"github.com/arduino/arduino-cli/internal/go-configmap"
......@@ -36,7 +35,6 @@ func TestConfiguration(t *testing.T) {
yml, err := yaml.Marshal(c)
require.NoError(t, err)
fmt.Println(string(yml))
d := configmap.New()
err = yaml.Unmarshal(yml, &d)
......@@ -109,13 +107,11 @@ func TestMerge(t *testing.T) {
f := configmap.New()
f.Set("fooz.bar", 10)
require.Error(t, c.Merge(f))
fmt.Println(c.Merge(f))
require.EqualError(t, c.Merge(f), "invalid types for key 'bar': got string but want int")
g := configmap.New()
g.Set("fooz.bart", "baz")
require.Error(t, c.Merge(g))
fmt.Println(c.Merge(g))
require.EqualError(t, c.Merge(g), "target key do not exist: 'bart'")
}
func TestAllKeys(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment