Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

rc: listremotes should send an empty array instead of nil

n4n5db4812fbfa5e
diff --git a/fs/config/rc.go b/fs/config/rc.go
index 07f309e76..c87dcb318 100644
--- a/fs/config/rc.go
+++ b/fs/config/rc.go
@@ -106,6 +106,9 @@ See the [listremotes](/commands/rclone_listremotes/) command for more informatio
// including any defined by environment variables.
func rcListRemotes(ctx context.Context, in rc.Params) (out rc.Params, err error) {
remoteNames := GetRemoteNames()
+ if remoteNames == nil {
+ remoteNames = []string{}
+ }
out = rc.Params{
"remotes": remoteNames,
}
diff --git a/fs/config/rc_test.go b/fs/config/rc_test.go
index 68c127a03..b21b8af50 100644
--- a/fs/config/rc_test.go
+++ b/fs/config/rc_test.go
@@ -138,6 +138,22 @@ func TestRc(t *testing.T) {
assert.Nil(t, out)
assert.Equal(t, "", config.GetValue(testName, "type"))
assert.Equal(t, "", config.GetValue(testName, "test_key"))
+
+ t.Run("ListRemotes empty not nil", func(t *testing.T) {
+ call := rc.Calls.Get("config/listremotes")
+ assert.NotNil(t, call)
+ in := rc.Params{}
+ out, err := call.Fn(context.Background(), in)
+ require.NoError(t, err)
+ require.NotNil(t, out)
+
+ var remotes []string
+ err = out.GetStruct("remotes", &remotes)
+ require.NoError(t, err)
+
+ assert.NotNil(t, remotes)
+ assert.Empty(t, remotes)
+ })
}
func TestRcProviders(t *testing.T) {