From f88a5542cf2471842e9a4165daa9d9067fe0e4e3 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 8 Aug 2020 18:02:18 +0100 Subject: [PATCH] test: move test commands under "rclone test" and make them visible --- CONTRIBUTING.md | 4 +-- cmd/all/all.go | 5 ++-- cmd/{ => test}/info/all.sh | 0 cmd/{ => test}/info/info.go | 30 ++++++++++++++----- .../info/internal/build_csv/main.go | 2 +- cmd/{ => test}/info/internal/internal.go | 0 cmd/{ => test}/info/test.cmd | 0 cmd/{ => test}/info/test.sh | 0 .../memtest.go => test/memory/memory.go} | 10 +++---- cmd/test/test.go | 27 +++++++++++++++++ 10 files changed, 60 insertions(+), 18 deletions(-) rename cmd/{ => test}/info/all.sh (100%) rename cmd/{ => test}/info/info.go (92%) rename cmd/{ => test}/info/internal/build_csv/main.go (98%) rename cmd/{ => test}/info/internal/internal.go (100%) rename cmd/{ => test}/info/test.cmd (100%) rename cmd/{ => test}/info/test.sh (100%) rename cmd/{memtest/memtest.go => test/memory/memory.go} (85%) create mode 100644 cmd/test/test.go diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f071716a..96df841e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -333,8 +333,8 @@ Getting going * Try to implement as many optional methods as possible as it makes the remote more usable. * Use lib/encoder to make sure we can encode any path name and `rclone info` to help determine the encodings needed * `rclone purge -v TestRemote:rclone-info` - * `rclone info --remote-encoding None -vv --write-json remote.json TestRemote:rclone-info` - * `go run cmd/info/internal/build_csv/main.go -o remote.csv remote.json` + * `rclone test info --all --remote-encoding None -vv --write-json remote.json TestRemote:rclone-info` + * `go run cmd/test/info/internal/build_csv/main.go -o remote.csv remote.json` * open `remote.csv` in a spreadsheet and examine Unit tests diff --git a/cmd/all/all.go b/cmd/all/all.go index c3ad8bc78..6e195eff6 100644 --- a/cmd/all/all.go +++ b/cmd/all/all.go @@ -25,7 +25,6 @@ import ( _ "github.com/rclone/rclone/cmd/genautocomplete" _ "github.com/rclone/rclone/cmd/gendocs" _ "github.com/rclone/rclone/cmd/hashsum" - _ "github.com/rclone/rclone/cmd/info" _ "github.com/rclone/rclone/cmd/link" _ "github.com/rclone/rclone/cmd/listremotes" _ "github.com/rclone/rclone/cmd/ls" @@ -34,7 +33,6 @@ import ( _ "github.com/rclone/rclone/cmd/lsjson" _ "github.com/rclone/rclone/cmd/lsl" _ "github.com/rclone/rclone/cmd/md5sum" - _ "github.com/rclone/rclone/cmd/memtest" _ "github.com/rclone/rclone/cmd/mkdir" _ "github.com/rclone/rclone/cmd/mount" _ "github.com/rclone/rclone/cmd/mount2" @@ -54,6 +52,9 @@ import ( _ "github.com/rclone/rclone/cmd/sha1sum" _ "github.com/rclone/rclone/cmd/size" _ "github.com/rclone/rclone/cmd/sync" + _ "github.com/rclone/rclone/cmd/test" + _ "github.com/rclone/rclone/cmd/test/info" + _ "github.com/rclone/rclone/cmd/test/memory" _ "github.com/rclone/rclone/cmd/touch" _ "github.com/rclone/rclone/cmd/tree" _ "github.com/rclone/rclone/cmd/version" diff --git a/cmd/info/all.sh b/cmd/test/info/all.sh similarity index 100% rename from cmd/info/all.sh rename to cmd/test/info/all.sh diff --git a/cmd/info/info.go b/cmd/test/info/info.go similarity index 92% rename from cmd/info/info.go rename to cmd/test/info/info.go index c2006f20a..377353c36 100644 --- a/cmd/info/info.go +++ b/cmd/test/info/info.go @@ -1,7 +1,7 @@ package info // FIXME once translations are implemented will need a no-escape -// option for Put so we can make these tests work agaig +// option for Put so we can make these tests work again import ( "bytes" @@ -9,6 +9,7 @@ import ( "encoding/json" "fmt" "io" + "log" "os" "path" "regexp" @@ -20,7 +21,8 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/cmd" - "github.com/rclone/rclone/cmd/info/internal" + "github.com/rclone/rclone/cmd/test" + "github.com/rclone/rclone/cmd/test/info/internal" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/hash" @@ -35,6 +37,7 @@ var ( checkControl bool checkLength bool checkStreaming bool + all bool uploadWait time.Duration positionLeftRe = regexp.MustCompile(`(?s)^(.*)-position-left-([[:xdigit:]]+)$`) positionMiddleRe = regexp.MustCompile(`(?s)^position-middle-([[:xdigit:]]+)-(.*)-$`) @@ -42,14 +45,15 @@ var ( ) func init() { - cmd.Root.AddCommand(commandDefinition) + test.Command.AddCommand(commandDefinition) cmdFlags := commandDefinition.Flags() flags.StringVarP(cmdFlags, &writeJSON, "write-json", "", "", "Write results to file.") - flags.BoolVarP(cmdFlags, &checkNormalization, "check-normalization", "", true, "Check UTF-8 Normalization.") - flags.BoolVarP(cmdFlags, &checkControl, "check-control", "", true, "Check control characters.") + flags.BoolVarP(cmdFlags, &checkNormalization, "check-normalization", "", false, "Check UTF-8 Normalization.") + flags.BoolVarP(cmdFlags, &checkControl, "check-control", "", false, "Check control characters.") flags.DurationVarP(cmdFlags, &uploadWait, "upload-wait", "", 0, "Wait after writing a file.") - flags.BoolVarP(cmdFlags, &checkLength, "check-length", "", true, "Check max filename length.") - flags.BoolVarP(cmdFlags, &checkStreaming, "check-streaming", "", true, "Check uploads with indeterminate file size.") + flags.BoolVarP(cmdFlags, &checkLength, "check-length", "", false, "Check max filename length.") + flags.BoolVarP(cmdFlags, &checkStreaming, "check-streaming", "", false, "Check uploads with indeterminate file size.") + flags.BoolVarP(cmdFlags, &all, "all", "", false, "Run all tests.") } var commandDefinition = &cobra.Command{ @@ -59,10 +63,20 @@ var commandDefinition = &cobra.Command{ to write to the paths passed in and how long they can be. It can take some time. It will write test files into the remote:path passed in. It outputs a bit of go code for each one. + +**NB** this can create undeletable files and other hazards - use with care `, - Hidden: true, Run: func(command *cobra.Command, args []string) { cmd.CheckArgs(1, 1e6, command, args) + if !checkNormalization && !checkControl && !checkLength && !checkStreaming && !all { + log.Fatalf("no tests selected - select a test or use -all") + } + if all { + checkNormalization = true + checkControl = true + checkLength = true + checkStreaming = true + } for i := range args { f := cmd.NewFsDir(args[i : i+1]) cmd.Run(false, false, command, func() error { diff --git a/cmd/info/internal/build_csv/main.go b/cmd/test/info/internal/build_csv/main.go similarity index 98% rename from cmd/info/internal/build_csv/main.go rename to cmd/test/info/internal/build_csv/main.go index 8e173dbdd..96aa20a19 100644 --- a/cmd/info/internal/build_csv/main.go +++ b/cmd/test/info/internal/build_csv/main.go @@ -11,7 +11,7 @@ import ( "sort" "strconv" - "github.com/rclone/rclone/cmd/info/internal" + "github.com/rclone/rclone/cmd/test/info/internal" ) func main() { diff --git a/cmd/info/internal/internal.go b/cmd/test/info/internal/internal.go similarity index 100% rename from cmd/info/internal/internal.go rename to cmd/test/info/internal/internal.go diff --git a/cmd/info/test.cmd b/cmd/test/info/test.cmd similarity index 100% rename from cmd/info/test.cmd rename to cmd/test/info/test.cmd diff --git a/cmd/info/test.sh b/cmd/test/info/test.sh similarity index 100% rename from cmd/info/test.sh rename to cmd/test/info/test.sh diff --git a/cmd/memtest/memtest.go b/cmd/test/memory/memory.go similarity index 85% rename from cmd/memtest/memtest.go rename to cmd/test/memory/memory.go index f31b1a5e2..0fbf216fc 100644 --- a/cmd/memtest/memtest.go +++ b/cmd/test/memory/memory.go @@ -1,4 +1,4 @@ -package memtest +package memory import ( "context" @@ -6,19 +6,19 @@ import ( "sync" "github.com/rclone/rclone/cmd" + "github.com/rclone/rclone/cmd/test" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" ) func init() { - cmd.Root.AddCommand(commandDefinition) + test.Command.AddCommand(commandDefinition) } var commandDefinition = &cobra.Command{ - Use: "memtest remote:path", - Short: `Load all the objects at remote:path and report memory stats.`, - Hidden: true, + Use: "memory remote:path", + Short: `Load all the objects at remote:path into memory and report memory stats.`, Run: func(command *cobra.Command, args []string) { cmd.CheckArgs(1, 1, command, args) fsrc := cmd.NewFsSrc(args) diff --git a/cmd/test/test.go b/cmd/test/test.go new file mode 100644 index 000000000..39f5ccb29 --- /dev/null +++ b/cmd/test/test.go @@ -0,0 +1,27 @@ +package test + +import ( + "github.com/rclone/rclone/cmd" + "github.com/spf13/cobra" +) + +func init() { + cmd.Root.AddCommand(Command) +} + +// Command definition for cobra +var Command = &cobra.Command{ + Use: "test ", + Short: `Run a test command`, + Long: `Rclone test is used to run test commands. + +Select which test comand you want with the subcommand, eg + + rclone test memory remote: + +Each subcommand has its own options which you can see in their help. + +**NB** Be careful running these commands, they may do strange things +so reading their documentation first is recommended. +`, +}