1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

test: replace defer cleanup with t.Cleanup

Reference: https://pkg.go.dev/testing#T.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-12-08 20:43:53 +08:00
committed by Nick Craig-Wood
parent be783a1856
commit 8e507075d1
34 changed files with 217 additions and 555 deletions

View File

@@ -12,14 +12,14 @@ import (
"github.com/stretchr/testify/require"
)
func rcNewRun(t *testing.T, method string) (r *fstest.Run, vfs *VFS, cleanup func(), call *rc.Call) {
func rcNewRun(t *testing.T, method string) (r *fstest.Run, vfs *VFS, call *rc.Call) {
if *fstest.RemoteName != "" {
t.Skip("Skipping test on non local remote")
}
r, vfs, cleanup = newTestVFS(t)
r, vfs = newTestVFS(t)
call = rc.Calls.Get(method)
assert.NotNil(t, call)
return r, vfs, cleanup, call
return r, vfs, call
}
func TestRcGetVFS(t *testing.T) {
@@ -29,8 +29,7 @@ func TestRcGetVFS(t *testing.T) {
assert.Contains(t, err.Error(), "no VFS active")
assert.Nil(t, vfs)
r, vfs2, cleanup := newTestVFS(t)
defer cleanup()
r, vfs2 := newTestVFS(t)
vfs, err = getVFS(in)
require.NoError(t, err)
@@ -65,8 +64,7 @@ func TestRcGetVFS(t *testing.T) {
}
func TestRcForget(t *testing.T) {
r, vfs, cleanup, call := rcNewRun(t, "vfs/forget")
defer cleanup()
r, vfs, call := rcNewRun(t, "vfs/forget")
_, _ = r, vfs
in := rc.Params{"fs": fs.ConfigString(r.Fremote)}
out, err := call.Fn(context.Background(), in)
@@ -78,8 +76,7 @@ func TestRcForget(t *testing.T) {
}
func TestRcRefresh(t *testing.T) {
r, vfs, cleanup, call := rcNewRun(t, "vfs/refresh")
defer cleanup()
r, vfs, call := rcNewRun(t, "vfs/refresh")
_, _ = r, vfs
in := rc.Params{"fs": fs.ConfigString(r.Fremote)}
out, err := call.Fn(context.Background(), in)
@@ -93,8 +90,7 @@ func TestRcRefresh(t *testing.T) {
}
func TestRcPollInterval(t *testing.T) {
r, vfs, cleanup, call := rcNewRun(t, "vfs/poll-interval")
defer cleanup()
r, vfs, call := rcNewRun(t, "vfs/poll-interval")
_ = vfs
if r.Fremote.Features().ChangeNotify == nil {
t.Skip("ChangeNotify not supported")
@@ -106,8 +102,7 @@ func TestRcPollInterval(t *testing.T) {
}
func TestRcList(t *testing.T) {
r, vfs, cleanup, call := rcNewRun(t, "vfs/list")
defer cleanup()
r, vfs, call := rcNewRun(t, "vfs/list")
_ = vfs
out, err := call.Fn(context.Background(), nil)
@@ -121,8 +116,7 @@ func TestRcList(t *testing.T) {
}
func TestRcStats(t *testing.T) {
r, vfs, cleanup, call := rcNewRun(t, "vfs/stats")
defer cleanup()
r, vfs, call := rcNewRun(t, "vfs/stats")
out, err := call.Fn(context.Background(), nil)
require.NoError(t, err)
assert.Equal(t, fs.ConfigString(r.Fremote), out["fs"])