1 package storage
2
3
4
5
6 import (
7 "io/ioutil"
8 "net/http"
9 "testing"
10
11 chk "gopkg.in/check.v1"
12 )
13
14 type CopyBlobSuite struct{}
15
16 var _ = chk.Suite(&CopyBlobSuite{})
17
18 func (s *CopyBlobSuite) TestBlobCopy(c *chk.C) {
19 if testing.Short() {
20 c.Skip("skipping blob copy in short mode, no SLA on async operation")
21 }
22
23 cli := getBlobClient(c)
24 rec := cli.client.appendRecorder(c)
25 defer rec.Stop()
26
27 cnt := cli.GetContainerReference(containerName(c))
28 c.Assert(cnt.Create(nil), chk.IsNil)
29 defer cnt.Delete(nil)
30
31 srcBlob := cnt.GetBlobReference(blobName(c, "src"))
32 dstBlob := cnt.GetBlobReference(blobName(c, "dst"))
33 body := content(1024)
34
35 c.Assert(srcBlob.putSingleBlockBlob(body), chk.IsNil)
36 defer srcBlob.Delete(nil)
37
38 c.Assert(dstBlob.Copy(srcBlob.GetURL(), nil), chk.IsNil)
39 defer dstBlob.Delete(nil)
40
41 resp, err := dstBlob.Get(nil)
42 c.Assert(err, chk.IsNil)
43
44 b, err := ioutil.ReadAll(resp)
45 defer resp.Close()
46 c.Assert(err, chk.IsNil)
47 c.Assert(b, chk.DeepEquals, body)
48 }
49
50 func (s *CopyBlobSuite) TestStartBlobCopy(c *chk.C) {
51 if testing.Short() {
52 c.Skip("skipping blob copy in short mode, no SLA on async operation")
53 }
54
55 cli := getBlobClient(c)
56 rec := cli.client.appendRecorder(c)
57 defer rec.Stop()
58
59 cnt := cli.GetContainerReference(containerName(c))
60 c.Assert(cnt.Create(nil), chk.IsNil)
61 defer cnt.Delete(nil)
62
63 srcBlob := cnt.GetBlobReference(blobName(c, "src"))
64 dstBlob := cnt.GetBlobReference(blobName(c, "dst"))
65 body := content(1024)
66
67 c.Assert(srcBlob.putSingleBlockBlob(body), chk.IsNil)
68 defer srcBlob.Delete(nil)
69
70
71
72 copyID, err := dstBlob.StartCopy(srcBlob.GetURL(), nil)
73 c.Assert(copyID, chk.NotNil)
74 c.Assert(err, chk.IsNil)
75 }
76
77
78
79
80 func (s *CopyBlobSuite) TestAbortBlobCopy(c *chk.C) {
81 if testing.Short() {
82 c.Skip("skipping blob copy in short mode, no SLA on async operation")
83 }
84
85 cli := getBlobClient(c)
86 rec := cli.client.appendRecorder(c)
87 defer rec.Stop()
88
89 cnt := cli.GetContainerReference(containerName(c))
90 c.Assert(cnt.Create(nil), chk.IsNil)
91 defer cnt.Delete(nil)
92
93 srcBlob := cnt.GetBlobReference(blobName(c, "src"))
94 dstBlob := cnt.GetBlobReference(blobName(c, "dst"))
95 body := content(1024)
96
97 c.Assert(srcBlob.putSingleBlockBlob(body), chk.IsNil)
98 defer srcBlob.Delete(nil)
99
100
101
102 copyID, err := dstBlob.StartCopy(srcBlob.GetURL(), nil)
103 c.Assert(copyID, chk.NotNil)
104 c.Assert(err, chk.IsNil)
105
106 err = dstBlob.WaitForCopy(copyID)
107 c.Assert(err, chk.IsNil)
108
109
110 err = dstBlob.AbortCopy(copyID, nil)
111
112
113 c.Assert(err.(AzureStorageServiceError).StatusCode, chk.Equals, http.StatusConflict)
114 }
115
116 func (s *CopyBlobSuite) TestIncrementalCopyBlobNoTimeout(c *chk.C) {
117 if testing.Short() {
118 c.Skip("skipping blob copy in short mode, no SLA on async operation")
119 }
120
121 cli := getBlobClient(c)
122 rec := cli.client.appendRecorder(c)
123 defer rec.Stop()
124
125 cnt := cli.GetContainerReference(containerName(c))
126 options := CreateContainerOptions{
127 Access: ContainerAccessTypeBlob,
128 }
129 c.Assert(cnt.Create(&options), chk.IsNil)
130 defer cnt.Delete(nil)
131
132 b := cnt.GetBlobReference(blobName(c, "src"))
133 size := int64(10 * 1024 * 1024)
134 b.Properties.ContentLength = size
135 c.Assert(b.PutPageBlob(nil), chk.IsNil)
136
137 snapshotTime, err := b.CreateSnapshot(nil)
138 c.Assert(err, chk.IsNil)
139 c.Assert(snapshotTime, chk.NotNil)
140
141 u := b.GetURL()
142 destBlob := cnt.GetBlobReference(blobName(c, "dst"))
143 copyID, err := destBlob.IncrementalCopyBlob(u, *snapshotTime, nil)
144 c.Assert(copyID, chk.NotNil)
145 c.Assert(err, chk.IsNil)
146 }
147
148 func (s *CopyBlobSuite) TestIncrementalCopyBlobWithTimeout(c *chk.C) {
149 cli := getBlobClient(c)
150 rec := cli.client.appendRecorder(c)
151 defer rec.Stop()
152
153 cnt := cli.GetContainerReference(containerName(c))
154 options := CreateContainerOptions{
155 Access: ContainerAccessTypeBlob,
156 }
157 c.Assert(cnt.Create(&options), chk.IsNil)
158 defer cnt.Delete(nil)
159
160 b := cnt.GetBlobReference(blobName(c, "src"))
161 size := int64(10 * 1024 * 1024)
162 b.Properties.ContentLength = size
163 c.Assert(b.PutPageBlob(nil), chk.IsNil)
164
165 snapshotTime, err := b.CreateSnapshot(nil)
166 c.Assert(err, chk.IsNil)
167 c.Assert(snapshotTime, chk.NotNil)
168
169 u := b.GetURL()
170 destBlob := cnt.GetBlobReference(blobName(c, "dst"))
171 copyID, err := destBlob.IncrementalCopyBlob(u, *snapshotTime, &IncrementalCopyOptions{Timeout: 30})
172 c.Assert(copyID, chk.NotNil)
173 c.Assert(err, chk.IsNil)
174 }
175
View as plain text