1
mirror of https://github.com/rclone/rclone synced 2024-12-22 13:03:02 +01:00

Add optional interface DirCacheFlush for making the tests more reliable

This is defined for the users of dircache drive, onedrive, and acd.

This helps fix the DirMove tests on acd.
This commit is contained in:
Nick Craig-Wood 2016-12-09 15:39:29 +00:00
parent d911bf3889
commit 48a2e3844d
5 changed files with 45 additions and 14 deletions

View File

@ -636,6 +636,11 @@ func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error) {
}
fs.Debug(src, "Attempting to move to %q", remote)
return srcObj.move(remote, false)
// DirCacheFlush resets the directory cache - used in testing as an
// optional interface
func (f *Fs) DirCacheFlush() {
f.dirCache.ResetRoot()
}
// DirMove moves src directory to this remote using server side move
@ -1122,8 +1127,9 @@ var (
_ fs.Fs = (*Fs)(nil)
_ fs.Purger = (*Fs)(nil)
// _ fs.Copier = (*Fs)(nil)
_ fs.Mover = (*Fs)(nil)
_ fs.DirMover = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{}
_ fs.Mover = (*Fs)(nil)
_ fs.DirMover = (*Fs)(nil)
_ fs.DirCacheFlusher = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{}
)

View File

@ -799,6 +799,12 @@ func (f *Fs) DirMove(src fs.Fs) error {
return nil
}
// DirCacheFlush resets the directory cache - used in testing as an
// optional interface
func (f *Fs) DirCacheFlush() {
f.dirCache.ResetRoot()
}
// Hashes returns the supported hash sets.
func (f *Fs) Hashes() fs.HashSet {
return fs.HashSet(fs.HashMD5)
@ -1079,12 +1085,13 @@ func (o *Object) MimeType() string {
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
_ fs.Purger = (*Fs)(nil)
_ fs.Copier = (*Fs)(nil)
_ fs.Mover = (*Fs)(nil)
_ fs.DirMover = (*Fs)(nil)
_ fs.PutUncheckeder = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{}
_ fs.Fs = (*Fs)(nil)
_ fs.Purger = (*Fs)(nil)
_ fs.Copier = (*Fs)(nil)
_ fs.Mover = (*Fs)(nil)
_ fs.DirMover = (*Fs)(nil)
_ fs.DirCacheFlusher = (*Fs)(nil)
_ fs.PutUncheckeder = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{}
)

View File

@ -275,6 +275,13 @@ type UnWrapper interface {
UnWrap() Fs
}
// DirCacheFlusher is an optional interface for Fs
type DirCacheFlusher interface {
// DirCacheFlush resets the directory cache - used in testing
// as an optional interface
DirCacheFlush()
}
// PutUncheckeder is an optional interface for Fs
type PutUncheckeder interface {
// Put in to the remote path with the modTime given of the given size

View File

@ -175,6 +175,10 @@ func CheckListingWithPrecision(t *testing.T, f fs.Fs, items []Item, expectedDirs
sleep *= 2
t.Logf("Sleeping for %v for list eventual consistency: %d/%d", sleep, i, retries)
time.Sleep(sleep)
if do, ok := f.(fs.DirCacheFlusher); ok {
t.Logf("Flushing the directory cache")
do.DirCacheFlush()
}
}
for _, obj := range objs {
require.NotNil(t, obj)

View File

@ -635,6 +635,12 @@ func (f *Fs) Purge() error {
return f.purgeCheck("", false)
}
// DirCacheFlush resets the directory cache - used in testing as an
// optional interface
func (f *Fs) DirCacheFlush() {
f.dirCache.ResetRoot()
}
// Hashes returns the supported hash sets.
func (f *Fs) Hashes() fs.HashSet {
return fs.HashSet(fs.HashSHA1)
@ -960,6 +966,7 @@ var (
_ fs.Copier = (*Fs)(nil)
// _ fs.Mover = (*Fs)(nil)
// _ fs.DirMover = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{}
_ fs.DirCacheFlusher = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{}
)