From 85f222af30d1c8b83efb639709e2c9822d79e9b0 Mon Sep 17 00:00:00 2001 From: MatteoPologruto Date: Tue, 14 Nov 2023 16:32:25 +0100 Subject: [PATCH 1/3] Enable empty configuration merging --- commands/daemon/settings.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commands/daemon/settings.go b/commands/daemon/settings.go index 151ce9da61a..2d8b9ca9039 100644 --- a/commands/daemon/settings.go +++ b/commands/daemon/settings.go @@ -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 } From 96de3f79a939dad1c6f90687faed20dce247736d Mon Sep 17 00:00:00 2001 From: MatteoPologruto Date: Mon, 25 Sep 2023 17:58:26 +0200 Subject: [PATCH 2/3] Test that a default configuration is correctly deleted --- commands/daemon/settings_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/commands/daemon/settings_test.go b/commands/daemon/settings_test.go index c5366e179b5..b35dec54f7f 100644 --- a/commands/daemon/settings_test.go +++ b/commands/daemon/settings_test.go @@ -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() } From c7719c184332c1dbf3abad95141b23268c24af3d Mon Sep 17 00:00:00 2001 From: MatteoPologruto Date: Mon, 8 Jan 2024 09:53:54 +0100 Subject: [PATCH 3/3] Reset config after every merge test --- commands/daemon/settings_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/daemon/settings_test.go b/commands/daemon/settings_test.go index b35dec54f7f..93f49174e50 100644 --- a/commands/daemon/settings_test.go +++ b/commands/daemon/settings_test.go @@ -120,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) {