Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fstests: add test for 0 sized streaming upload

Nick Craig-Woodad2bb86d8cd6
diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go
index 4f12391b0..b76a59d41 100644
--- a/fstest/fstests/fstests.go
+++ b/fstest/fstests/fstests.go
@@ -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
- 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))
+ 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))
+ })
+ }
})
// TestInternal calls InternalTest() on the Fs