Skip to content

Commit db4812f

Browse files
rc: listremotes should send an empty array instead of nil
1 parent ff9cbab commit db4812f

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

fs/config/rc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ See the [listremotes](/commands/rclone_listremotes/) command for more informatio
106106
// including any defined by environment variables.
107107
func rcListRemotes(ctx context.Context, in rc.Params) (out rc.Params, err error) {
108108
remoteNames := GetRemoteNames()
109+
if remoteNames == nil {
110+
remoteNames = []string{}
111+
}
109112
out = rc.Params{
110113
"remotes": remoteNames,
111114
}

fs/config/rc_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ func TestRc(t *testing.T) {
138138
assert.Nil(t, out)
139139
assert.Equal(t, "", config.GetValue(testName, "type"))
140140
assert.Equal(t, "", config.GetValue(testName, "test_key"))
141+
142+
t.Run("ListRemotes empty not nil", func(t *testing.T) {
143+
call := rc.Calls.Get("config/listremotes")
144+
assert.NotNil(t, call)
145+
in := rc.Params{}
146+
out, err := call.Fn(context.Background(), in)
147+
require.NoError(t, err)
148+
require.NotNil(t, out)
149+
150+
var remotes []string
151+
err = out.GetStruct("remotes", &remotes)
152+
require.NoError(t, err)
153+
154+
assert.NotNil(t, remotes)
155+
assert.Empty(t, remotes)
156+
})
141157
}
142158

143159
func TestRcProviders(t *testing.T) {

0 commit comments

Comments
 (0)