fstest

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package fstest provides utilities for testing the Fs

Index

Constants

This section is empty.

Variables

View Source
var (
	RemoteName      = flag.String("remote", "", "Remote to test with, defaults to local filesystem")
	Verbose         = flag.Bool("verbose", false, "Set to enable logging")
	DumpHeaders     = flag.Bool("dump-headers", false, "Set to dump headers (needs -verbose)")
	DumpBodies      = flag.Bool("dump-bodies", false, "Set to dump bodies (needs -verbose)")
	Individual      = flag.Bool("individual", false, "Make individual bucket/container/directory for each test - much slower")
	LowLevelRetries = flag.Int("low-level-retries", 10, "Number of low level retries")
	UseListR        = flag.Bool("fast-list", false, "Use recursive list if available. Uses more memory but fewer transactions.")
	// SizeLimit signals tests to skip maximum test file size and skip inappropriate runs
	SizeLimit = flag.Int64("size-limit", 0, "Limit maximum test file size")
	// ListRetries is the number of times to retry a listing to overcome eventual consistency
	ListRetries = flag.Int("list-retries", 3, "Number or times to retry listing")
	// MatchTestRemote matches the remote names used for testing
	MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{12}$`)
)

Globals

Functions

func AssertTimeEqualWithPrecision

func AssertTimeEqualWithPrecision(t *testing.T, remote string, want, got time.Time, precision time.Duration)

AssertTimeEqualWithPrecision checks that want is within precision of got, asserting that with t and logging remote

func CheckDirModTime

func CheckDirModTime(ctx context.Context, t *testing.T, f fs.Fs, dir fs.Directory, wantT time.Time)

CheckDirModTime checks the modtime on the directory

func CheckEntryMetadata

func CheckEntryMetadata(ctx context.Context, t *testing.T, f fs.Fs, entry fs.DirEntry, wantMeta fs.Metadata)

CheckEntryMetadata checks the metadata on the directory

This checks a limited set of metadata on the directory

func CheckItems

func CheckItems(t *testing.T, f fs.Fs, items ...Item)

CheckItems checks the fs to see if it has only the items passed in using a precision of fs.Config.ModifyWindow

func CheckItemsWithPrecision

func CheckItemsWithPrecision(t *testing.T, f fs.Fs, precision time.Duration, items ...Item)

CheckItemsWithPrecision checks the fs with the specified precision to see if it has the expected items.

func CheckListing

func CheckListing(t *testing.T, f fs.Fs, items []Item)

CheckListing checks the fs to see if it has the expected contents

func CheckListingWithPrecision

func CheckListingWithPrecision(t *testing.T, f fs.Fs, items []Item, expectedDirs []string, precision time.Duration)

CheckListingWithPrecision checks the fs to see if it has the expected contents with the given precision.

If expectedDirs is non nil then we check those too. Note that no directories returned is also OK as some remotes don't return directories.

func CheckListingWithRoot

func CheckListingWithRoot(t *testing.T, f fs.Fs, dir string, items []Item, expectedDirs []string, precision time.Duration)

CheckListingWithRoot checks the fs to see if it has the expected contents with the given precision.

If expectedDirs is non nil then we check those too. Note that no directories returned is also OK as some remotes don't return directories.

dir is the directory used for the listing.

func CheckTimeEqualWithPrecision

func CheckTimeEqualWithPrecision(t0, t1 time.Time, precision time.Duration) (time.Duration, bool)

CheckTimeEqualWithPrecision checks the times are equal within the precision, returns the delta and a flag

func CompareItems

func CompareItems(t *testing.T, entries fs.DirEntries, items []Item, expectedDirs []string, precision time.Duration, what string)

CompareItems compares a set of DirEntries to a slice of items and a list of dirs The modtimes are compared with the precision supplied

func Gz

func Gz(t *testing.T, s string) string

Gz returns a compressed version of its input string

func Initialise

func Initialise()

Initialise rclone for testing

func LocalRemote

func LocalRemote() (path string, err error)

LocalRemote creates a temporary directory name for local remotes

func NewDirectory

func NewDirectory(ctx context.Context, t *testing.T, f fs.Fs, remote string) fs.Directory

NewDirectory finds the directory with remote in f

One day this will be an rclone primitive

func NewDirectoryRetries

func NewDirectoryRetries(ctx context.Context, t *testing.T, f fs.Fs, remote string, retries int) (fs.Directory, error)

NewDirectoryRetries finds the directory with remote in f

If directory can't be found it returns an error wrapping fs.ErrorDirNotFound

One day this will be an rclone primitive

func NewObject

func NewObject(ctx context.Context, t *testing.T, f fs.Fs, remote string) fs.Object

NewObject finds the object on the remote

func Normalize

func Normalize(name string) string

Normalize runs a utf8 normalization on the string if running on OS X. This is because OS X denormalizes file names it writes to the local file system.

func Purge

func Purge(f fs.Fs)

Purge is a simplified re-implementation of operations.Purge for the test routine cleanup to avoid circular dependencies.

It logs errors rather than returning them

func RandomRemote

func RandomRemote() (fs.Fs, string, func(), error)

RandomRemote makes a random bucket or subdirectory on the remote from the -remote parameter

Call the finalise function returned to Purge the fs at the end (and the parent if necessary)

Returns the remote, its url, a finaliser and an error

func RandomRemoteName

func RandomRemoteName(remoteName string) (string, string, error)

RandomRemoteName makes a random bucket or subdirectory name

Returns a random remote name plus the leaf name

func TestMain

func TestMain(m *testing.M)

TestMain drives the tests

func Time

func Time(timeString string) time.Time

Time parses a time string or logs a fatal error

Types

type Item

type Item struct {
	Path    string
	Hashes  map[hash.Type]string
	ModTime time.Time
	Size    int64
}

Item represents an item for checking

func NewItem

func NewItem(Path, Content string, modTime time.Time) Item

NewItem creates an item from a string content

func (*Item) Check

func (i *Item) Check(t *testing.T, obj fs.Object, precision time.Duration)

Check checks all the attributes of the object are correct

func (*Item) CheckHashes

func (i *Item) CheckHashes(t *testing.T, obj fs.Object)

CheckHashes checks all the hashes the object supports are correct

func (*Item) CheckModTime

func (i *Item) CheckModTime(t *testing.T, obj fs.Object, modTime time.Time, precision time.Duration)

CheckModTime checks the mod time to the given precision

type Items

type Items struct {
	// contains filtered or unexported fields
}

Items represents all items for checking

func NewItems

func NewItems(items []Item) *Items

NewItems makes an Items

func (*Items) Done

func (is *Items) Done(t *testing.T)

Done checks all finished

func (*Items) Find

func (is *Items) Find(t *testing.T, obj fs.Object, precision time.Duration)

Find checks off an item

type Run

type Run struct {
	LocalName   string
	Flocal      fs.Fs
	Fremote     fs.Fs
	FremoteName string
	Precision   time.Duration

	Logf, Fatalf func(text string, args ...interface{})
	// contains filtered or unexported fields
}

Run holds the remotes for a test run

func NewRun

func NewRun(t *testing.T) *Run

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

func NewRunIndividual

func NewRunIndividual(t *testing.T) *Run

NewRunIndividual as per NewRun but makes an individual remote for this test

func (*Run) CheckDirectoryModTimes

func (r *Run) CheckDirectoryModTimes(t *testing.T, names ...string)

CheckDirectoryModTimes checks that the directory names in r.Flocal has the correct modtime compared to r.Fremote

func (*Run) CheckLocalItems

func (r *Run) CheckLocalItems(t *testing.T, items ...Item)

CheckLocalItems checks the local fs with proper precision to see if it has the expected items.

func (*Run) CheckLocalListing

func (r *Run) CheckLocalListing(t *testing.T, items []Item, expectedDirs []string)

CheckLocalListing checks the local fs with proper precision to see if it has the expected contents.

If expectedDirs is non nil then we check those too. Note that no directories returned is also OK as some remotes don't return directories.

func (*Run) CheckRemoteItems

func (r *Run) CheckRemoteItems(t *testing.T, items ...Item)

CheckRemoteItems checks the remote fs with proper precision to see if it has the expected items.

func (*Run) CheckRemoteListing

func (r *Run) CheckRemoteListing(t *testing.T, items []Item, expectedDirs []string)

CheckRemoteListing checks the remote fs with proper precision to see if it has the expected contents.

If expectedDirs is non nil then we check those too. Note that no directories returned is also OK as some remotes don't return directories.

func (*Run) CheckWithDuplicates

func (r *Run) CheckWithDuplicates(t *testing.T, items ...Item)

CheckWithDuplicates does a test but allows duplicates

func (*Run) Finalise

func (r *Run) Finalise()

Finalise cleans the remote and local

func (*Run) ForceMkdir

func (r *Run) ForceMkdir(ctx context.Context, f fs.Fs)

ForceMkdir creates the remote

func (*Run) Mkdir

func (r *Run) Mkdir(ctx context.Context, f fs.Fs)

Mkdir creates the remote if it hasn't been created already

func (*Run) RenameFile

func (r *Run) RenameFile(item Item, newpath string) Item

RenameFile renames a file in local

func (*Run) WriteBoth

func (r *Run) WriteBoth(ctx context.Context, remote, content string, modTime time.Time) Item

WriteBoth calls WriteObject and WriteFile with the same arguments

func (*Run) WriteFile

func (r *Run) WriteFile(filePath, content string, t time.Time) Item

WriteFile writes a file to local

func (*Run) WriteObject

func (r *Run) WriteObject(ctx context.Context, remote, content string, modTime time.Time) Item

WriteObject writes an object to the remote

func (*Run) WriteObjectTo

func (r *Run) WriteObjectTo(ctx context.Context, f fs.Fs, remote, content string, modTime time.Time, useUnchecked bool) Item

WriteObjectTo writes an object to the fs, remote passed in

func (*Run) WriteUncheckedObject

func (r *Run) WriteUncheckedObject(ctx context.Context, remote, content string, modTime time.Time) Item

WriteUncheckedObject writes an object to the remote not checking for duplicates

Directories

Path Synopsis
Package fstests provides generic integration tests for the Fs and Object interfaces.
Package fstests provides generic integration tests for the Fs and Object interfaces.
Package mockdir makes a mock fs.Directory object
Package mockdir makes a mock fs.Directory object
Package mockfs provides mock Fs for testing.
Package mockfs provides mock Fs for testing.
Package mockobject provides a mock object which can be created from a string
Package mockobject provides a mock object which can be created from a string
Run tests for all the remotes.
Run tests for all the remotes.
Package testserver starts and stops test servers if required
Package testserver starts and stops test servers if required
Package testy contains test utilities for rclone
Package testy contains test utilities for rclone

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL