fstests: add test for 0 sized streaming upload
This commit is contained in:
parent
eb10ac346f
commit
ad2bb86d8c
1 changed files with 33 additions and 29 deletions
|
@ -18,6 +18,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -1571,36 +1572,39 @@ func Run(t *testing.T, opt *Opt) {
|
||||||
t.Skip("FS has no PutStream interface")
|
t.Skip("FS has no PutStream interface")
|
||||||
}
|
}
|
||||||
|
|
||||||
file := fstest.Item{
|
for _, contentSize := range []int{0, 100} {
|
||||||
ModTime: fstest.Time("2001-02-03T04:05:06.499999999Z"),
|
t.Run(strconv.Itoa(contentSize), func(t *testing.T) {
|
||||||
Path: "piped data.txt",
|
file := fstest.Item{
|
||||||
Size: -1, // use unknown size during upload
|
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
|
// TestInternal calls InternalTest() on the Fs
|
||||||
|
|
Loading…
Add table
Reference in a new issue