From f92beb4e14c8301beba70dd0ac06fcc88dd04e3f Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 14 Nov 2018 17:14:02 +0000 Subject: [PATCH] fstest: Fix TestPurge causing errors with subsequent tests on azure Before this change TestPurge would remove a container and subsequent tests would fail because the container was still being deleted so couldn't be created. This was fixed by introducing an fstest.NewRunIndividual() test runner for TestPurge which causes the test to be run on a new container. --- fs/operations/operations_test.go | 2 +- fstest/run.go | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go index 620175c91..95f4586e5 100644 --- a/fs/operations/operations_test.go +++ b/fs/operations/operations_test.go @@ -404,7 +404,7 @@ func TestRcat(t *testing.T) { } func TestPurge(t *testing.T) { - r := fstest.NewRun(t) + r := fstest.NewRunIndividual(t) // make new container (azureblob has delayed mkdir after rmdir) defer r.Finalise() r.Mkdir(r.Fremote) diff --git a/fstest/run.go b/fstest/run.go index 23872e1b5..dda6d4570 100644 --- a/fstest/run.go +++ b/fstest/run.go @@ -121,16 +121,17 @@ func retry(t *testing.T, what string, f func() error) { t.Logf("%s failed: %v", what, err) } -// NewRun initialise the remote and local for testing and returns a -// run object. Call this from the tests. +// newRunIndividual initialise the remote and local for testing and +// returns a run object. Pass in true to make individual tests or +// false to use the global one. // // r.Flocal is an empty local Fs // r.Fremote is an empty remote Fs // // Finalise() will tidy them away when done. -func NewRun(t *testing.T) *Run { +func newRunIndividual(t *testing.T, individual bool) *Run { var r *Run - if *Individual { + if individual { r = newRun() } else { // If not individual, use the global one with the clean method overridden @@ -176,6 +177,22 @@ func NewRun(t *testing.T) *Run { return r } +// NewRun initialise the remote and local for testing and returns a +// run object. Call this from the tests. +// +// r.Flocal is an empty local Fs +// r.Fremote is an empty remote Fs +// +// Finalise() will tidy them away when done. +func NewRun(t *testing.T) *Run { + return newRunIndividual(t, *Individual) +} + +// NewRunIndividual as per NewRun but makes an individual remote for this test +func NewRunIndividual(t *testing.T) *Run { + return newRunIndividual(t, true) +} + // RenameFile renames a file in local func (r *Run) RenameFile(item Item, newpath string) Item { oldFilepath := path.Join(r.LocalName, item.Path)