Unverified Commit 74a99aae authored by MatteoPologruto's avatar MatteoPologruto Committed by GitHub

Allow empty configuration merging (#2432)

* Enable empty configuration merging

* Test that a default configuration is correctly deleted

* Reset config after every merge test
parent bd028443
......@@ -79,9 +79,13 @@ func (s *ArduinoCoreServerImpl) SettingsMerge(ctx context.Context, req *rpc.Sett
// Set each value individually.
// This is done because Viper ignores empty strings or maps when
// using the MergeConfigMap function.
updatedSettings := configuration.Init("")
for k, v := range mapped {
configuration.Settings.Set(k, v)
updatedSettings.Set(k, v)
}
configPath := configuration.Settings.ConfigFileUsed()
updatedSettings.SetConfigFile(configPath)
configuration.Settings = updatedSettings
return &rpc.SettingsMergeResponse{}, nil
}
......
......@@ -81,6 +81,13 @@ func TestMerge(t *testing.T) {
require.Equal(t, "", configuration.Settings.GetString("foo"))
require.Equal(t, false, configuration.Settings.GetBool("sketch.always_export_binaries"))
bulkSettings = `{"network": {}}`
res, err = svc.SettingsMerge(context.Background(), &rpc.SettingsMergeRequest{JsonData: bulkSettings})
require.NotNil(t, res)
require.NoError(t, err)
require.Equal(t, "", configuration.Settings.GetString("proxy"))
reset()
}
......@@ -113,6 +120,8 @@ func TestGetMergedValue(t *testing.T) {
res, err = svc.SettingsGetValue(context.Background(), key)
require.NoError(t, err)
require.Equal(t, `"bar"`, res.GetJsonData())
reset()
}
func TestGetValueNotFound(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