mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
cmdtest: end-to-end test for commands, flags and environment variables
There was no easy way to automatically test the end-to-end functionality of commands, flags, environment variables etc. The need for end-to-end testing was highlighted by the issues fixed in #5341. There was no automated test to continually verify current behaviour, nor a framework to quickly test the correctness of the fixes. This change adds an end-to-end testing framework in the cmdtest folder. It has some simple examples in func TestCmdTest in cmdtest_test.go. The tests should be readable by anybody familiar with rclone and look like this: // Test the rclone version command with debug logging (-vv) out, err = rclone("version", "-vv") if assert.NoError(t, err) { assert.Contains(t, out, "rclone v") assert.Contains(t, out, "os/version:") assert.Contains(t, out, " DEBUG : ") } The end-to-end tests are executed just like the Go unit tests, that is: go test ./cmdtest -v The change also contains a thorough test of environment variables in environment_test.go. Thanks to @ncw for encouragement and introduction to the TestMain trick.
This commit is contained in:
committed by
Nick Craig-Wood
parent
58c99427b3
commit
5e91b93e59
19
cmdtest/cmdtest.go
Normal file
19
cmdtest/cmdtest.go
Normal file
@@ -0,0 +1,19 @@
|
||||
// Package cmdtest creates a testable interface to rclone main
|
||||
//
|
||||
// The interface is used to perform end-to-end test of
|
||||
// commands, flags, environment variables etc.
|
||||
//
|
||||
package cmdtest
|
||||
|
||||
// The rest of this file is a 1:1 copy from rclone.go
|
||||
|
||||
import (
|
||||
_ "github.com/rclone/rclone/backend/all" // import all backends
|
||||
"github.com/rclone/rclone/cmd"
|
||||
_ "github.com/rclone/rclone/cmd/all" // import all commands
|
||||
_ "github.com/rclone/rclone/lib/plugin" // import plugins
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Main()
|
||||
}
|
||||
Reference in New Issue
Block a user