Fixed off-by-1 error in UploadStreamToBlockBlob and changed response type
This commit is contained in:
Родитель
19832016ae
Коммит
82d537cd67
|
@ -366,7 +366,7 @@ func (t *uploadStreamToBlockBlobOptions) start(ctx context.Context) (interface{}
|
|||
|
||||
func (t *uploadStreamToBlockBlobOptions) chunk(ctx context.Context, num uint32, buffer []byte) error {
|
||||
if num == 0 && len(buffer) < t.o.BufferSize {
|
||||
// If whole payload fits in 1 block, dont' stage it; End will upload it with 1 I/O operation
|
||||
// If whole payload fits in 1 block, don't stage it; End will upload it with 1 I/O operation
|
||||
t.firstBlock = buffer
|
||||
return nil
|
||||
}
|
||||
|
@ -391,8 +391,8 @@ func (t *uploadStreamToBlockBlobOptions) end(ctx context.Context) (interface{},
|
|||
}
|
||||
// Multiple blocks staged, commit them all now
|
||||
blockID := newUuidBlockID(t.blockIDPrefix)
|
||||
blockIDs := make([]string, t.maxBlockNum)
|
||||
for bn := uint32(0); bn < t.maxBlockNum; bn++ {
|
||||
blockIDs := make([]string, t.maxBlockNum + 1)
|
||||
for bn := uint32(0); bn <= t.maxBlockNum; bn++ {
|
||||
blockIDs[bn] = blockID.WithBlockNumber(bn).ToBase64()
|
||||
}
|
||||
return t.b.CommitBlockList(ctx, blockIDs, t.o.BlobHTTPHeaders, t.o.Metadata, t.o.AccessConditions)
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package azblob_test
|
||||
|
||||
import (
|
||||
chk "gopkg.in/check.v1"
|
||||
"github.com/Azure/azure-storage-blob-go/2017-07-29/azblob"
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func (s *aztestsSuite) TestUploadStreamToBlockBlobInChunks(c *chk.C) {
|
||||
// Set up test container
|
||||
bsu := getBSU()
|
||||
containerURL, _ := createNewContainer(c, bsu)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
// Set up test blob
|
||||
blobURL, _ := getBlockBlobURL(c, containerURL)
|
||||
|
||||
// Create a some data to test the upload stream
|
||||
blobSize := 8 * 1024
|
||||
blobData := make([]byte, blobSize, blobSize)
|
||||
for i := range blobData {
|
||||
blobData[i] = byte('a' + i%26)
|
||||
}
|
||||
|
||||
// Perform UploadStreamToBlockBlob
|
||||
uploadResp, err := azblob.UploadStreamToBlockBlob(ctx, bytes.NewReader(blobData), blobURL,
|
||||
azblob.UploadStreamToBlockBlobOptions{BufferSize: 1024, MaxBuffers: 3})
|
||||
|
||||
// Assert that upload was successful
|
||||
c.Assert(err, chk.Equals, nil)
|
||||
c.Assert(uploadResp.StatusCode(), chk.Equals, 201)
|
||||
|
||||
// Download the blob and assert that the content is correct
|
||||
downloadResponse, err := blobURL.Download(ctx, 0, 0, azblob.BlobAccessConditions{}, false)
|
||||
c.Assert(err, chk.IsNil)
|
||||
actualBlobData, err := ioutil.ReadAll(downloadResponse.Response().Body)
|
||||
c.Assert(len(actualBlobData), chk.Equals, blobSize)
|
||||
c.Assert(actualBlobData, chk.DeepEquals, blobData)
|
||||
}
|
||||
|
||||
func (s *aztestsSuite) TestUploadStreamToBlockBlobSingleIO(c *chk.C) {
|
||||
// Set up test container
|
||||
bsu := getBSU()
|
||||
containerURL, _ := createNewContainer(c, bsu)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
// Set up test blob
|
||||
blobURL, _ := getBlockBlobURL(c, containerURL)
|
||||
|
||||
// Create a some data to test the upload stream
|
||||
blobSize := 8 * 1024
|
||||
blobData := make([]byte, blobSize, blobSize)
|
||||
for i := range blobData {
|
||||
blobData[i] = byte('a' + i%26)
|
||||
}
|
||||
|
||||
// Perform UploadStreamToBlockBlob
|
||||
uploadResp, err := azblob.UploadStreamToBlockBlob(ctx, bytes.NewReader(blobData), blobURL,
|
||||
azblob.UploadStreamToBlockBlobOptions{BufferSize: 10 * 1024, MaxBuffers: 3})
|
||||
|
||||
// Assert that upload was successful
|
||||
c.Assert(err, chk.Equals, nil)
|
||||
c.Assert(uploadResp.StatusCode(), chk.Equals, 201)
|
||||
|
||||
// Download the blob and assert that the content is correct
|
||||
downloadResponse, err := blobURL.Download(ctx, 0, 0, azblob.BlobAccessConditions{}, false)
|
||||
c.Assert(err, chk.IsNil)
|
||||
actualBlobData, err := ioutil.ReadAll(downloadResponse.Response().Body)
|
||||
c.Assert(len(actualBlobData), chk.Equals, blobSize)
|
||||
c.Assert(actualBlobData, chk.DeepEquals, blobData)
|
||||
}
|
Загрузка…
Ссылка в новой задаче