mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 08:58:26 +08:00
fstest: remove spurious contents return from PutTestContents and friends
This commit is contained in:
parent
35f24d5b84
commit
461d041c4d
|
@ -59,7 +59,7 @@ var mtime1 = fstest.Time("2001-02-03T04:05:06.499999999Z")
|
|||
|
||||
func testPutFile(ctx context.Context, t *testing.T, f fs.Fs, name, contents, message string, check bool) fs.Object {
|
||||
item := fstest.Item{Path: name, ModTime: mtime1}
|
||||
_, obj := fstests.PutTestContents(ctx, t, f, &item, contents, check)
|
||||
obj := fstests.PutTestContents(ctx, t, f, &item, contents, check)
|
||||
assert.NotNil(t, obj, message)
|
||||
return obj
|
||||
}
|
||||
|
@ -440,7 +440,7 @@ func testSmallFileInternals(t *testing.T, f *Fs) {
|
|||
checkSmallFile := func(name, contents string) {
|
||||
filename := path.Join(dir, name)
|
||||
item := fstest.Item{Path: filename, ModTime: modTime}
|
||||
_, put := fstests.PutTestContents(ctx, t, f, &item, contents, false)
|
||||
put := fstests.PutTestContents(ctx, t, f, &item, contents, false)
|
||||
assert.NotNil(t, put)
|
||||
checkSmallFileInternals(put)
|
||||
checkContents(put, contents)
|
||||
|
@ -489,7 +489,7 @@ func testPreventCorruption(t *testing.T, f *Fs) {
|
|||
|
||||
newFile := func(name string) fs.Object {
|
||||
item := fstest.Item{Path: path.Join(dir, name), ModTime: modTime}
|
||||
_, obj := fstests.PutTestContents(ctx, t, f, &item, contents, true)
|
||||
obj := fstests.PutTestContents(ctx, t, f, &item, contents, true)
|
||||
require.NotNil(t, obj)
|
||||
return obj
|
||||
}
|
||||
|
@ -599,7 +599,7 @@ func testChunkNumberOverflow(t *testing.T, f *Fs) {
|
|||
newFile := func(f fs.Fs, name string) (obj fs.Object, filename string, txnID string) {
|
||||
filename = path.Join(dir, name)
|
||||
item := fstest.Item{Path: filename, ModTime: modTime}
|
||||
_, obj = fstests.PutTestContents(ctx, t, f, &item, contents, true)
|
||||
obj = fstests.PutTestContents(ctx, t, f, &item, contents, true)
|
||||
require.NotNil(t, obj)
|
||||
if chunkObj, isChunkObj := obj.(*Object); isChunkObj {
|
||||
txnID = chunkObj.xactID
|
||||
|
@ -716,7 +716,7 @@ func testFutureProof(t *testing.T, f *Fs) {
|
|||
name = f.makeChunkName(name, part-1, "", "")
|
||||
}
|
||||
item := fstest.Item{Path: name, ModTime: modTime}
|
||||
_, obj := fstests.PutTestContents(ctx, t, f.base, &item, data, true)
|
||||
obj := fstests.PutTestContents(ctx, t, f.base, &item, data, true)
|
||||
assert.NotNil(t, obj, msg)
|
||||
}
|
||||
|
||||
|
@ -790,7 +790,7 @@ func testBackwardsCompatibility(t *testing.T, f *Fs) {
|
|||
newFile := func(f fs.Fs, name string) (fs.Object, string) {
|
||||
filename := path.Join(dir, name)
|
||||
item := fstest.Item{Path: filename, ModTime: modTime}
|
||||
_, obj := fstests.PutTestContents(ctx, t, f, &item, contents, true)
|
||||
obj := fstests.PutTestContents(ctx, t, f, &item, contents, true)
|
||||
require.NotNil(t, obj)
|
||||
return obj, filename
|
||||
}
|
||||
|
@ -844,7 +844,7 @@ func testChunkerServerSideMove(t *testing.T, f *Fs) {
|
|||
modTime := fstest.Time("2001-02-03T04:05:06.499999999Z")
|
||||
item := fstest.Item{Path: "movefile", ModTime: modTime}
|
||||
contents := "abcdef"
|
||||
_, file := fstests.PutTestContents(ctx, t, fs1, &item, contents, true)
|
||||
file := fstests.PutTestContents(ctx, t, fs1, &item, contents, true)
|
||||
|
||||
dstOverwritten, _ := fs2.NewObject(ctx, "movefile")
|
||||
dstFile, err := operations.Move(ctx, fs2, dstOverwritten, "movefile", file)
|
||||
|
|
|
@ -378,9 +378,9 @@ func (f *Fs) InternalTestUnTrash(t *testing.T) {
|
|||
// Make some objects, one in a subdir
|
||||
contents := random.String(100)
|
||||
file1 := fstest.NewItem("trashDir/toBeTrashed", contents, time.Now())
|
||||
_, obj1 := fstests.PutTestContents(ctx, t, f, &file1, contents, false)
|
||||
obj1 := fstests.PutTestContents(ctx, t, f, &file1, contents, false)
|
||||
file2 := fstest.NewItem("trashDir/subdir/toBeTrashed", contents, time.Now())
|
||||
_, _ = fstests.PutTestContents(ctx, t, f, &file2, contents, false)
|
||||
_ = fstests.PutTestContents(ctx, t, f, &file2, contents, false)
|
||||
|
||||
// Check objects
|
||||
checkObjects := func() {
|
||||
|
@ -496,7 +496,7 @@ func (f *Fs) InternalTestAgeQuery(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
file1 := fstest.Item{ModTime: time.Now(), Path: "agequery.txt"}
|
||||
_, _ = fstests.PutTestContents(defCtx, t, tempFs1, &file1, "abcxyz", true)
|
||||
_ = fstests.PutTestContents(defCtx, t, tempFs1, &file1, "abcxyz", true)
|
||||
|
||||
// validate sync/copy
|
||||
const timeQuery = "(modifiedTime >= '"
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
func putFile(ctx context.Context, t *testing.T, f fs.Fs, name, data string) fs.Object {
|
||||
mtime1 := fstest.Time("2001-02-03T04:05:06.499999999Z")
|
||||
item := fstest.Item{Path: name, ModTime: mtime1}
|
||||
_, o := fstests.PutTestContents(ctx, t, f, &item, data, true)
|
||||
o := fstests.PutTestContents(ctx, t, f, &item, data, true)
|
||||
require.NotNil(t, o)
|
||||
return o
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ func (f *Fs) TestInternalReadOnly(t *testing.T) {
|
|||
// Put a file onto the read only fs
|
||||
contents := random.String(50)
|
||||
file1 := fstest.NewItem(dir+"/file.txt", contents, time.Now())
|
||||
_, obj1 := fstests.PutTestContents(ctx, t, rofs, &file1, contents, true)
|
||||
obj1 := fstests.PutTestContents(ctx, t, rofs, &file1, contents, true)
|
||||
|
||||
// Check read from readonly fs via union
|
||||
o, err := f.NewObject(ctx, file1.Path)
|
||||
|
@ -109,14 +109,14 @@ func TestMoveCopy(t *testing.T) {
|
|||
// Put a file onto the local fs
|
||||
contentsLocal := random.String(50)
|
||||
fileLocal := fstest.NewItem("local.txt", contentsLocal, time.Now())
|
||||
_, _ = fstests.PutTestContents(ctx, t, fLocal, &fileLocal, contentsLocal, true)
|
||||
_ = fstests.PutTestContents(ctx, t, fLocal, &fileLocal, contentsLocal, true)
|
||||
objLocal, err := f.NewObject(ctx, fileLocal.Path)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Put a file onto the memory fs
|
||||
contentsMemory := random.String(60)
|
||||
fileMemory := fstest.NewItem("memory.txt", contentsMemory, time.Now())
|
||||
_, _ = fstests.PutTestContents(ctx, t, fMemory, &fileMemory, contentsMemory, true)
|
||||
_ = fstests.PutTestContents(ctx, t, fMemory, &fileMemory, contentsMemory, true)
|
||||
objMemory, err := f.NewObject(ctx, fileMemory.Path)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -297,7 +297,7 @@ func TestHashSumsWithErrors(t *testing.T) {
|
|||
// Make a test file
|
||||
content := "-"
|
||||
item1 := fstest.NewItem("file1", content, t1)
|
||||
_, _ = fstests.PutTestContents(ctx, t, memFs, &item1, content, true)
|
||||
_ = fstests.PutTestContents(ctx, t, memFs, &item1, content, true)
|
||||
|
||||
// MemoryFS supports MD5
|
||||
buf := &bytes.Buffer{}
|
||||
|
|
|
@ -178,7 +178,7 @@ var _ fs.MimeTyper = (*objectInfoWithMimeType)(nil)
|
|||
// putTestContentsMimeType puts file with given contents to the remote and checks it but unlike TestPutLarge doesn't remove
|
||||
//
|
||||
// it uploads the object with the mimeType passed in if set
|
||||
func putTestContentsMimeType(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item, contents string, check bool, mimeType string) (string, fs.Object) {
|
||||
func putTestContentsMimeType(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item, contents string, check bool, mimeType string) fs.Object {
|
||||
var (
|
||||
err error
|
||||
obj fs.Object
|
||||
|
@ -204,22 +204,24 @@ func putTestContentsMimeType(ctx context.Context, t *testing.T, f fs.Fs, file *f
|
|||
obj = findObject(ctx, t, f, file.Path)
|
||||
file.Check(t, obj, f.Precision())
|
||||
}
|
||||
return contents, obj
|
||||
return obj
|
||||
}
|
||||
|
||||
// PutTestContents puts file with given contents to the remote and checks it but unlike TestPutLarge doesn't remove
|
||||
func PutTestContents(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item, contents string, check bool) (string, fs.Object) {
|
||||
func PutTestContents(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item, contents string, check bool) fs.Object {
|
||||
return putTestContentsMimeType(ctx, t, f, file, contents, check, "")
|
||||
}
|
||||
|
||||
// testPut puts file with random contents to the remote
|
||||
func testPut(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item) (string, fs.Object) {
|
||||
return PutTestContents(ctx, t, f, file, random.String(100), true)
|
||||
contents := random.String(100)
|
||||
return contents, PutTestContents(ctx, t, f, file, contents, true)
|
||||
}
|
||||
|
||||
// testPutMimeType puts file with random contents to the remote and the mime type given
|
||||
func testPutMimeType(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item, mimeType string) (string, fs.Object) {
|
||||
return putTestContentsMimeType(ctx, t, f, file, random.String(100), true, mimeType)
|
||||
contents := random.String(100)
|
||||
return contents, putTestContentsMimeType(ctx, t, f, file, contents, true, mimeType)
|
||||
}
|
||||
|
||||
// TestPutLarge puts file to the remote, checks it and removes it on success.
|
||||
|
|
Loading…
Reference in New Issue
Block a user