Skip to content

Commit 9d208b4

Browse files
committed
bisync: test that every flag can be set through the rc
Before this change, nothing checked that the rc `sync/bisync` call accepted every bisync flag, so the rc could fall behind the command line as flags were added, as in #7799. After this change, `TestRcFlagParity` passes each non-hidden bisync flag to the rc, under the parameter name `rc.md` uses, with a value of the wrong type. Every getter `rcBisync` uses rejects it, so the call fails only if the parameter is read, and the test names any flag the rc doesn't handle.
1 parent 708d696 commit 9d208b4

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

‎cmd/bisync/rc_test.go‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"strings"
89
"testing"
910
"time"
1011

12+
"github.com/rclone/rclone/cmd"
1113
"github.com/rclone/rclone/fs"
1214
"github.com/rclone/rclone/fs/rc"
1315
"github.com/rclone/rclone/fs/rc/jobs"
1416
"github.com/rclone/rclone/fstest"
17+
"github.com/spf13/pflag"
1518
"github.com/stretchr/testify/assert"
1619
"github.com/stretchr/testify/require"
1720
)
@@ -42,7 +45,9 @@ func newRcBisyncCtx(ctx context.Context, t *testing.T, n int) (path1, path2 stri
4245
runIn := func(ctx context.Context, in rc.Params) error {
4346
in["path1"] = path1
4447
in["path2"] = path2
45-
in["workdir"] = workdir
48+
if _, ok := in["workdir"]; !ok {
49+
in["workdir"] = workdir
50+
}
4651
_, _, err := jobs.NewJob(ctx, call.Fn, in)
4752
return err
4853
}
@@ -231,3 +236,30 @@ func TestRcEnums(t *testing.T) {
231236
assert.NoFileExists(t, filepath.Join(path2, "new.txt"))
232237
})
233238
}
239+
240+
// rcParamName returns the rc parameter name for a flag, as help.go does for rc.md
241+
func rcParamName(flag string) string {
242+
words := strings.Split(flag, "-")
243+
for i := 1; i < len(words); i++ {
244+
words[i] = strings.ToUpper(words[i][:1]) + words[i][1:]
245+
}
246+
return strings.Join(words, "")
247+
}
248+
249+
// Test every bisync flag can be set through the rc
250+
func TestRcFlagParity(t *testing.T) {
251+
bisyncCmd, _, err := cmd.Root.Find([]string{"bisync"})
252+
require.NoError(t, err)
253+
bisyncCmd.Flags().VisitAll(func(flag *pflag.Flag) {
254+
if flag.Hidden {
255+
return
256+
}
257+
key := rcParamName(flag.Name)
258+
t.Run(key, func(t *testing.T) {
259+
_, _, run := newRcBisync(t, 1)
260+
// no rc getter accepts a map, so this only fails if rcBisync reads the param
261+
err := run(rc.Params{key: rc.Params{"wrong": "type"}})
262+
assert.ErrorContains(t, err, key, "no rc parameter for --%s", flag.Name)
263+
})
264+
})
265+
}

0 commit comments

Comments
 (0)