Skip to content

Commit

Permalink
Allow empty configuration merging (#2432)
Browse files Browse the repository at this point in the history
* Enable empty configuration merging

* Test that a default configuration is correctly deleted

* Reset config after every merge test
  • Loading branch information
MatteoPologruto committed Jan 11, 2024
1 parent bd02844 commit 74a99aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion commands/daemon/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions commands/daemon/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 74a99aa

Please sign in to comment.