Skip to content

Commit

Permalink
Adjusted unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Dec 11, 2024
1 parent ab8c357 commit ff3735f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
67 changes: 64 additions & 3 deletions commands/service_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,73 @@ func TestDelete(t *testing.T) {
srv := NewArduinoCoreServer()
loadConfig(t, srv, paths.New("testdata", "arduino-cli.yml"))

_, err := srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"})
// Check loaded config
resp, err := srv.ConfigurationSave(context.Background(), &rpc.ConfigurationSaveRequest{
SettingsFormat: "yaml",
})
require.NoError(t, err)
require.YAMLEq(t, `
board_manager:
additional_urls:
- http://foobar.com
- http://example.com
daemon:
port: "50051"
directories:
data: /home/massi/.arduino15
downloads: /home/massi/.arduino15/staging
logging:
file: ""
format: text
level: info
network:
proxy: "123"
`, resp.GetEncodedSettings())

// Check default and setted values
res, err := srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"})
require.NoError(t, err)
require.Equal(t, `{"proxy":"123"}`, res.GetEncodedValue())
// Maybe should be like this?
// require.Equal(t, `{"proxy":"123","connection_timeout":"1m0s"}`, res.GetEncodedValue())
res, err = srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network.connection_timeout"})
require.Equal(t, `"1m0s"`, res.GetEncodedValue()) // default value
require.NoError(t, err)

// Run deletion
_, err = srv.SettingsSetValue(context.Background(), &rpc.SettingsSetValueRequest{Key: "network", EncodedValue: ""})
require.NoError(t, err)
resp, err = srv.ConfigurationSave(context.Background(), &rpc.ConfigurationSaveRequest{
SettingsFormat: "yaml",
})
require.NoError(t, err)
require.YAMLEq(t, `
board_manager:
additional_urls:
- http://foobar.com
- http://example.com
_, err = srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"})
require.Error(t, err)
daemon:
port: "50051"
directories:
data: /home/massi/.arduino15
downloads: /home/massi/.arduino15/staging
logging:
file: ""
format: text
level: info
`, resp.GetEncodedSettings())
// Check default and setted values
res, err = srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network"})
require.NoError(t, err)
require.Equal(t, `{"connection_timeout":"1m0s"}`, res.GetEncodedValue())
res, err = srv.SettingsGetValue(context.Background(), &rpc.SettingsGetValueRequest{Key: "network.connection_timeout"})
require.Equal(t, `"1m0s"`, res.GetEncodedValue()) // default value
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions internal/cli/configuration/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func TestConnectionTimeout(t *testing.T) {

doRequest := func(timeout int) (*http.Response, time.Duration, error) {
settings := configuration.NewSettings()
settings.Set("network.proxy", ts.URL)
require.NoError(t, settings.Set("network.proxy", ts.URL))
if timeout != 0 {
settings.Set("network.connection_timeout", 2)
require.NoError(t, settings.Set("network.connection_timeout", "2s"))
}
client, err := settings.NewHttpClient()
require.NoError(t, err)
Expand Down

0 comments on commit ff3735f

Please sign in to comment.