1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
package storage
import (
"io/ioutil"
chk "gopkg.in/check.v1"
)
type AppendBlobSuite struct{}
var _ = chk.Suite(&AppendBlobSuite{})
func (s *AppendBlobSuite) TestPutAppendBlob(c *chk.C) {
cli := getBlobClient(c)
rec := cli.client.appendRecorder(c)
defer rec.Stop()
cnt := cli.GetContainerReference(containerName(c))
b := cnt.GetBlobReference(blobName(c))
c.Assert(cnt.Create(nil), chk.IsNil)
defer cnt.Delete(nil)
c.Assert(b.PutAppendBlob(nil), chk.IsNil)
// Verify
err := b.GetProperties(nil)
c.Assert(err, chk.IsNil)
c.Assert(b.Properties.ContentLength, chk.Equals, int64(0))
c.Assert(b.Properties.BlobType, chk.Equals, BlobTypeAppend)
}
func (s *AppendBlobSuite) TestPutAppendBlobAppendBlocks(c *chk.C) {
cli := getBlobClient(c)
rec := cli.client.appendRecorder(c)
defer rec.Stop()
cnt := cli.GetContainerReference(containerName(c))
b := cnt.GetBlobReference(blobName(c))
c.Assert(cnt.Create(nil), chk.IsNil)
defer cnt.Delete(nil)
c.Assert(b.PutAppendBlob(nil), chk.IsNil)
chunk1 := content(1024)
chunk2 := content(512)
// Append first block
c.Assert(b.AppendBlock(chunk1, nil), chk.IsNil)
// Verify contents
options := GetBlobRangeOptions{
Range: &BlobRange{
Start: 0,
End: uint64(len(chunk1) - 1),
},
}
out, err := b.GetRange(&options)
c.Assert(err, chk.IsNil)
defer out.Close()
blobContents, err := ioutil.ReadAll(out)
c.Assert(err, chk.IsNil)
c.Assert(blobContents, chk.DeepEquals, chunk1)
// Append second block
c.Assert(b.AppendBlock(chunk2, nil), chk.IsNil)
// Verify contents
options.Range.End = uint64(len(chunk1) + len(chunk2) - 1)
out, err = b.GetRange(&options)
c.Assert(err, chk.IsNil)
defer out.Close()
blobContents, err = ioutil.ReadAll(out)
c.Assert(err, chk.IsNil)
c.Assert(blobContents, chk.DeepEquals, append(chunk1, chunk2...))
}
func (s *StorageBlobSuite) TestPutAppendBlobSpecialChars(c *chk.C) {
cli := getBlobClient(c)
rec := cli.client.appendRecorder(c)
defer rec.Stop()
cnt := cli.GetContainerReference(containerName(c))
b := cnt.GetBlobReference(blobName(c))
c.Assert(cnt.Create(nil), chk.IsNil)
defer cnt.Delete(nil)
c.Assert(b.PutAppendBlob(nil), chk.IsNil)
// Verify metadata
err := b.GetProperties(nil)
c.Assert(err, chk.IsNil)
c.Assert(b.Properties.ContentLength, chk.Equals, int64(0))
c.Assert(b.Properties.BlobType, chk.Equals, BlobTypeAppend)
chunk1 := content(1024)
chunk2 := content(512)
// Append first block
c.Assert(b.AppendBlock(chunk1, nil), chk.IsNil)
// Verify contents
options := GetBlobRangeOptions{
Range: &BlobRange{
Start: 0,
End: uint64(len(chunk1) - 1),
},
}
out, err := b.GetRange(&options)
c.Assert(err, chk.IsNil)
defer out.Close()
blobContents, err := ioutil.ReadAll(out)
c.Assert(err, chk.IsNil)
c.Assert(blobContents, chk.DeepEquals, chunk1)
// Append second block
c.Assert(b.AppendBlock(chunk2, nil), chk.IsNil)
// Verify contents
options.Range.End = uint64(len(chunk1) + len(chunk2) - 1)
out, err = b.GetRange(&options)
c.Assert(err, chk.IsNil)
defer out.Close()
blobContents, err = ioutil.ReadAll(out)
c.Assert(err, chk.IsNil)
c.Assert(blobContents, chk.DeepEquals, append(chunk1, chunk2...))
}
|