1
mirror of https://github.com/rclone/rclone synced 2024-12-26 18:23:45 +01:00

fstests: add test for 0 sized streaming upload

This commit is contained in:
Nick Craig-Wood 2020-01-05 11:23:39 +00:00
parent eb10ac346f
commit ad2bb86d8c

View File

@ -18,6 +18,7 @@ import (
"path/filepath"
"reflect"
"sort"
"strconv"
"strings"
"testing"
"time"
@ -1571,36 +1572,39 @@ func Run(t *testing.T, opt *Opt) {
t.Skip("FS has no PutStream interface")
}
file := fstest.Item{
ModTime: fstest.Time("2001-02-03T04:05:06.499999999Z"),
Path: "piped data.txt",
Size: -1, // use unknown size during upload
for _, contentSize := range []int{0, 100} {
t.Run(strconv.Itoa(contentSize), func(t *testing.T) {
file := fstest.Item{
ModTime: fstest.Time("2001-02-03T04:05:06.499999999Z"),
Path: "piped data.txt",
Size: -1, // use unknown size during upload
}
var (
err error
obj fs.Object
uploadHash *hash.MultiHasher
)
retry(t, "PutStream", func() error {
contents := random.String(contentSize)
buf := bytes.NewBufferString(contents)
uploadHash = hash.NewMultiHasher()
in := io.TeeReader(buf, uploadHash)
file.Size = -1
obji := object.NewStaticObjectInfo(file.Path, file.ModTime, file.Size, true, nil, nil)
obj, err = remote.Features().PutStream(ctx, in, obji)
return err
})
file.Hashes = uploadHash.Sums()
file.Size = int64(contentSize) // use correct size when checking
file.Check(t, obj, remote.Precision())
// Re-read the object and check again
obj = findObject(ctx, t, remote, file.Path)
file.Check(t, obj, remote.Precision())
require.NoError(t, obj.Remove(ctx))
})
}
var (
err error
obj fs.Object
uploadHash *hash.MultiHasher
contentSize = 100
)
retry(t, "PutStream", func() error {
contents := random.String(contentSize)
buf := bytes.NewBufferString(contents)
uploadHash = hash.NewMultiHasher()
in := io.TeeReader(buf, uploadHash)
file.Size = -1
obji := object.NewStaticObjectInfo(file.Path, file.ModTime, file.Size, true, nil, nil)
obj, err = remote.Features().PutStream(ctx, in, obji)
return err
})
file.Hashes = uploadHash.Sums()
file.Size = int64(contentSize) // use correct size when checking
file.Check(t, obj, remote.Precision())
// Re-read the object and check again
obj = findObject(ctx, t, remote, file.Path)
file.Check(t, obj, remote.Precision())
require.NoError(t, obj.Remove(ctx))
})
// TestInternal calls InternalTest() on the Fs