sync: fix one transform test error failing all the following tests
Sync refuses to delete files when the global error stats are non-zero so a single backend error in one transform test made every following transform test in the same test binary fail with "not deleting files as there were IO errors". Reset the stats at the start of each test.
This commit is contained in:
@@ -26,6 +26,15 @@ import (
|
|||||||
|
|
||||||
var debug = ``
|
var debug = ``
|
||||||
|
|
||||||
|
// newTransformRun resets the global error stats, which Sync consults
|
||||||
|
// before deleting files, so that an error left over from an earlier
|
||||||
|
// test in this binary doesn't disable deletions in this one, then
|
||||||
|
// creates a new test run.
|
||||||
|
func newTransformRun(t *testing.T) *fstest.Run {
|
||||||
|
accounting.GlobalStats().ResetCounters()
|
||||||
|
return fstest.NewRun(t)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTransform(t *testing.T) {
|
func TestTransform(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
TransformOpt []string
|
TransformOpt []string
|
||||||
@@ -94,7 +103,7 @@ func TestTransform(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
defer r.Finalise()
|
defer r.Finalise()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@@ -228,7 +237,7 @@ func detectEncoding(s string) string {
|
|||||||
|
|
||||||
func TestTransformCopy(t *testing.T) {
|
func TestTransformCopy(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "all,suffix_keep_extension=_somesuffix")
|
err := transform.SetOptions(ctx, "all,suffix_keep_extension=_somesuffix")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
file1 := r.WriteFile("sub dir/hello world.txt", "hello world", t1)
|
file1 := r.WriteFile("sub dir/hello world.txt", "hello world", t1)
|
||||||
@@ -245,7 +254,7 @@ func TestTransformCopy(t *testing.T) {
|
|||||||
|
|
||||||
func TestDoubleTransform(t *testing.T) {
|
func TestDoubleTransform(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
|
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
file1 := r.WriteFile("toe/toe", "hello world", t1)
|
file1 := r.WriteFile("toe/toe", "hello world", t1)
|
||||||
@@ -262,7 +271,7 @@ func TestDoubleTransform(t *testing.T) {
|
|||||||
|
|
||||||
func TestFileTag(t *testing.T) {
|
func TestFileTag(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "file,prefix=tac", "file,prefix=tic")
|
err := transform.SetOptions(ctx, "file,prefix=tac", "file,prefix=tic")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
file1 := r.WriteFile("toe/toe/toe", "hello world", t1)
|
file1 := r.WriteFile("toe/toe/toe", "hello world", t1)
|
||||||
@@ -279,7 +288,7 @@ func TestFileTag(t *testing.T) {
|
|||||||
|
|
||||||
func TestNoTag(t *testing.T) {
|
func TestNoTag(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "prefix=tac", "prefix=tic")
|
err := transform.SetOptions(ctx, "prefix=tac", "prefix=tic")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
file1 := r.WriteFile("toe/toe/toe", "hello world", t1)
|
file1 := r.WriteFile("toe/toe/toe", "hello world", t1)
|
||||||
@@ -296,7 +305,7 @@ func TestNoTag(t *testing.T) {
|
|||||||
|
|
||||||
func TestDirTag(t *testing.T) {
|
func TestDirTag(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "dir,prefix=tac", "dir,prefix=tic")
|
err := transform.SetOptions(ctx, "dir,prefix=tac", "dir,prefix=tic")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
||||||
@@ -315,7 +324,7 @@ func TestDirTag(t *testing.T) {
|
|||||||
|
|
||||||
func TestAllTag(t *testing.T) {
|
func TestAllTag(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
|
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
||||||
@@ -336,7 +345,7 @@ func TestAllTag(t *testing.T) {
|
|||||||
|
|
||||||
func TestRunTwice(t *testing.T) {
|
func TestRunTwice(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "dir,prefix=tac", "dir,prefix=tic")
|
err := transform.SetOptions(ctx, "dir,prefix=tac", "dir,prefix=tic")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
file1 := r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
file1 := r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
||||||
@@ -377,7 +386,7 @@ func TestSyntax(t *testing.T) {
|
|||||||
|
|
||||||
func TestConflicting(t *testing.T) {
|
func TestConflicting(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "prefix=tac", "trimprefix=tac")
|
err := transform.SetOptions(ctx, "prefix=tac", "trimprefix=tac")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
file1 := r.WriteFile("toe/toe/toe", "hello world", t1)
|
file1 := r.WriteFile("toe/toe/toe", "hello world", t1)
|
||||||
@@ -395,7 +404,7 @@ func TestConflicting(t *testing.T) {
|
|||||||
|
|
||||||
func TestMove(t *testing.T) {
|
func TestMove(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
|
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
||||||
@@ -414,7 +423,7 @@ func TestMove(t *testing.T) {
|
|||||||
|
|
||||||
func TestTransformFile(t *testing.T) {
|
func TestTransformFile(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
|
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
||||||
@@ -443,7 +452,7 @@ func TestTransformFile(t *testing.T) {
|
|||||||
|
|
||||||
func TestManualTransformFile(t *testing.T) {
|
func TestManualTransformFile(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
|
|
||||||
r.Flocal.Features().DisableList([]string{"Copy", "Move"})
|
r.Flocal.Features().DisableList([]string{"Copy", "Move"})
|
||||||
r.Fremote.Features().DisableList([]string{"Copy", "Move"})
|
r.Fremote.Features().DisableList([]string{"Copy", "Move"})
|
||||||
@@ -476,7 +485,7 @@ func TestManualTransformFile(t *testing.T) {
|
|||||||
|
|
||||||
func TestBase64(t *testing.T) {
|
func TestBase64(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "all,base64encode")
|
err := transform.SetOptions(ctx, "all,base64encode")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
file1 := r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
file1 := r.WriteFile("toe/toe/toe.txt", "hello world", t1)
|
||||||
@@ -504,7 +513,7 @@ func TestBase64(t *testing.T) {
|
|||||||
|
|
||||||
func TestError(t *testing.T) {
|
func TestError(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := newTransformRun(t)
|
||||||
err := transform.SetOptions(ctx, "all,prefix=ta/c") // has illegal character
|
err := transform.SetOptions(ctx, "all,prefix=ta/c") // has illegal character
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
file1 := r.WriteFile("toe/toe/toe", "hello world", t1)
|
file1 := r.WriteFile("toe/toe/toe", "hello world", t1)
|
||||||
|
|||||||
Reference in New Issue
Block a user