Skip to content

Commit bb7585a

Browse files
authored
Recorded more storage tests (Azure#20582)
1 parent 7243f15 commit bb7585a

File tree

6 files changed

+36
-53
lines changed

6 files changed

+36
-53
lines changed

sdk/storage/azblob/appendblob/client_test.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockWithAutoGeneratedCRC64()
141141
// _require.Equal(resp.RawResponse.StatusCode, 201)
142142

143143
// test append block with valid CRC64 value
144-
readerToBody, body := testcommon.GetRandomDataAndReader(1024)
144+
readerToBody, body := testcommon.GetDataAndReader(testName, 1024)
145145
contentCRC64 := crc64.Checksum(body, shared.CRC64Table)
146146
appendBlockOptions := appendblob.AppendBlockOptions{
147147
TransactionalValidation: blob.TransferValidationTypeComputeCRC64(),
@@ -163,7 +163,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockWithAutoGeneratedCRC64()
163163
_require.Equal((*appendResp.Date).IsZero(), false)
164164

165165
// test bad CRC64
166-
readerToBody, body = testcommon.GetRandomDataAndReader(1024)
166+
readerToBody, body = testcommon.GetDataAndReader(testName, 1024)
167167
badCRC64 := rand.Uint64()
168168
_ = body
169169
appendBlockOptions = appendblob.AppendBlockOptions{
@@ -176,7 +176,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockWithAutoGeneratedCRC64()
176176
testcommon.ValidateBlobErrorCode(_require, err, bloberror.CRC64Mismatch)
177177
}
178178

179-
func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockWithMD5() {
179+
func (s *AppendBlobRecordedTestsSuite) TestAppendBlockWithMD5() {
180180
_require := require.New(s.T())
181181
testName := s.T().Name()
182182
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
@@ -193,7 +193,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockWithMD5() {
193193
// _require.Equal(resp.RawResponse.StatusCode, 201)
194194

195195
// test append block with valid MD5 value
196-
readerToBody, body := testcommon.GetRandomDataAndReader(1024)
196+
readerToBody, body := testcommon.GetDataAndReader(testName, 1024)
197197
md5Value := md5.Sum(body)
198198
_ = body
199199
contentMD5 := md5Value[:]
@@ -215,8 +215,8 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockWithMD5() {
215215
_require.Equal((*appendResp.Date).IsZero(), false)
216216

217217
// test append block with bad MD5 value
218-
readerToBody, body = testcommon.GetRandomDataAndReader(1024)
219-
_, badMD5 := testcommon.GetRandomDataAndReader(16)
218+
readerToBody, body = testcommon.GetDataAndReader(testName, 1024)
219+
_, badMD5 := testcommon.GetDataAndReader(testName, 16)
220220
_ = body
221221
appendBlockOptions = appendblob.AppendBlockOptions{
222222
TransactionalValidation: blob.TransferValidationTypeMD5(badMD5),
@@ -239,7 +239,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockFromURL() {
239239

240240
//ctx := ctx
241241
contentSize := 4 * 1024 // 4KB
242-
r, sourceData := testcommon.GetRandomDataAndReader(contentSize)
242+
r, sourceData := testcommon.GetDataAndReader(testName, contentSize)
243243
contentMD5 := md5.Sum(sourceData)
244244
srcBlob := containerClient.NewAppendBlobClient(testcommon.GenerateBlobName("appendsrc"))
245245
destBlob := containerClient.NewAppendBlobClient(testcommon.GenerateBlobName("appenddest"))
@@ -321,7 +321,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockFromURLWithMD5() {
321321

322322
//ctx := ctx
323323
contentSize := 4 * 1024 // 4KB
324-
r, sourceData := testcommon.GetRandomDataAndReader(contentSize)
324+
r, sourceData := testcommon.GetDataAndReader(testName, contentSize)
325325
contentMD5 := md5.Sum(sourceData)
326326
srcBlob := containerClient.NewAppendBlobClient(testcommon.GenerateBlobName("appendsrc"))
327327
destBlob := containerClient.NewAppendBlobClient(testcommon.GenerateBlobName("appenddest"))
@@ -397,7 +397,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockFromURLWithMD5() {
397397
_require.Equal(destBuffer, sourceData)
398398

399399
// Test append block from URL with bad MD5 value
400-
_, badMD5 := testcommon.GetRandomDataAndReader(16)
400+
_, badMD5 := testcommon.GetDataAndReader(testName, 16)
401401
var badMD5Validator blob.SourceContentValidationTypeMD5 = badMD5[:]
402402
appendBlockURLOptions = appendblob.AppendBlockFromURLOptions{
403403
Range: blob.HTTPRange{Offset: 0, Count: count},
@@ -414,10 +414,6 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockFromURLCopySourceAuth() {
414414
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
415415
_require.NoError(err)
416416

417-
// Random seed for data generation
418-
seed := int64(crc64.Checksum([]byte(testName), shared.CRC64Table))
419-
random := rand.New(rand.NewSource(seed))
420-
421417
// Getting AAD Authentication
422418
cred, err := testcommon.GetGenericTokenCredential()
423419
_require.NoError(err)
@@ -434,7 +430,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockFromURLCopySourceAuth() {
434430
_, err = srcABClient.Create(context.Background(), nil)
435431
_require.Nil(err)
436432
contentSize := 4 * 1024 // 4KB
437-
r, sourceData := testcommon.GetDataAndReader(random, contentSize)
433+
r, sourceData := testcommon.GetDataAndReader(testName, contentSize)
438434
_, err = srcABClient.AppendBlock(context.Background(), streaming.NopCloser(r), nil)
439435
_require.Nil(err)
440436
_, err = destABClient.Create(context.Background(), nil)
@@ -465,10 +461,6 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockFromURLCopySourceAuthNegat
465461
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
466462
_require.NoError(err)
467463

468-
// Random seed for data generation
469-
seed := int64(crc64.Checksum([]byte(testName), shared.CRC64Table))
470-
random := rand.New(rand.NewSource(seed))
471-
472464
containerName := testcommon.GenerateContainerName(testName)
473465
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
474466
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
@@ -481,7 +473,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockFromURLCopySourceAuthNegat
481473
_, err = srcABClient.Create(context.Background(), nil)
482474
_require.Nil(err)
483475
contentSize := 4 * 1024 // 4KB
484-
r, _ := testcommon.GetDataAndReader(random, contentSize)
476+
r, _ := testcommon.GetDataAndReader(testName, contentSize)
485477
_, err = srcABClient.AppendBlock(context.Background(), streaming.NopCloser(r), nil)
486478
_require.Nil(err)
487479
_, err = destABClient.Create(context.Background(), nil)

sdk/storage/azblob/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "go",
44
"TagPrefix": "go/storage/azblob",
5-
"Tag": "go/storage/azblob_cc6efe2d90"
5+
"Tag": "go/storage/azblob_37ff5d95f1"
66
}

sdk/storage/azblob/blob/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (s *BlobUnrecordedTestsSuite) TestCopyBlockBlobFromUrlSourceContentMD5() {
245245
_require.EqualValues(resp.ContentMD5, sourceContentMD5)
246246

247247
// Provide bad MD5 and make sure the copy fails
248-
_, badMD5 := testcommon.GetRandomDataAndReader(16)
248+
_, badMD5 := testcommon.GetDataAndReader(testName, 16)
249249
resp, err = destBlob.CopyFromURL(context.Background(), srcBlobURLWithSAS, &blob.CopyFromURLOptions{
250250
SourceContentMD5: badMD5,
251251
})
@@ -1077,7 +1077,7 @@ func (s *BlobUnrecordedTestsSuite) TestBlobAbortCopyInProgress() {
10771077

10781078
// Create a large blob that takes time to copy
10791079
blobSize := 8 * 1024 * 1024
1080-
blobReader, _ := testcommon.GetRandomDataAndReader(blobSize)
1080+
blobReader, _ := testcommon.GetDataAndReader(testName, blobSize)
10811081
_, err = bbClient.Upload(context.Background(), streaming.NopCloser(blobReader), nil)
10821082
_require.Nil(err)
10831083

sdk/storage/azblob/blockblob/client_test.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestStageBlockWithGeneratedCRC64() {
467467
}
468468

469469
// nolint
470-
func (s *BlockBlobUnrecordedTestsSuite) TestStageBlockWithMD5() {
470+
func (s *BlockBlobRecordedTestsSuite) TestStageBlockWithMD5() {
471471
_require := require.New(s.T())
472472
testName := s.T().Name()
473473
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
@@ -501,7 +501,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestStageBlockWithMD5() {
501501
_require.Equal((*putResp.Date).IsZero(), false)
502502

503503
// test put block with bad MD5 value
504-
_, badContent := testcommon.GetRandomDataAndReader(contentSize)
504+
_, badContent := testcommon.GetDataAndReader(testName, contentSize)
505505
badMD5Value := md5.Sum(badContent)
506506
badContentMD5 := badMD5Value[:]
507507

@@ -599,7 +599,7 @@ func setUpPutBlobFromURLTest(testName string, _require *require.Assertions, svcC
599599

600600
// Upload some data to source
601601
contentSize := 4 * 1024 // 4KB
602-
r, sourceData := testcommon.GetRandomDataAndReader(contentSize)
602+
r, sourceData := testcommon.GetDataAndReader(testName, contentSize)
603603
_, err := srcBBClient.Upload(context.Background(), streaming.NopCloser(r), nil)
604604
_require.Nil(err)
605605

@@ -796,7 +796,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestPutBlobFromUrlSourceContentMD5() {
796796
_require.EqualValues(resp.ContentMD5, sourceDataMD5Value[:])
797797

798798
// Try UploadBlobFromURL with bad MD5
799-
_, badMD5 := testcommon.GetRandomDataAndReader(16)
799+
_, badMD5 := testcommon.GetDataAndReader(testName, 16)
800800
options2 := blockblob.UploadBlobFromURLOptions{
801801
SourceContentMD5: badMD5,
802802
}
@@ -1180,10 +1180,6 @@ func (s *BlockBlobRecordedTestsSuite) TestPutBlobFromURLCopySourceAuth() {
11801180
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
11811181
_require.NoError(err)
11821182

1183-
// Random seed for data generation
1184-
seed := int64(crc64.Checksum([]byte(testName), shared.CRC64Table))
1185-
random := rand.New(rand.NewSource(seed))
1186-
11871183
// Getting AAD Authentication
11881184
cred, err := testcommon.GetGenericTokenCredential()
11891185
_require.NoError(err)
@@ -1198,7 +1194,7 @@ func (s *BlockBlobRecordedTestsSuite) TestPutBlobFromURLCopySourceAuth() {
11981194

11991195
// Upload some data to source
12001196
contentSize := 4 * 1024 // 4KB
1201-
r, sourceData := testcommon.GetDataAndReader(random, contentSize)
1197+
r, sourceData := testcommon.GetDataAndReader(testName, contentSize)
12021198
_, err = srcBBClient.Upload(context.Background(), streaming.NopCloser(r), nil)
12031199
_require.Nil(err)
12041200

@@ -1228,10 +1224,6 @@ func (s *BlockBlobRecordedTestsSuite) TestPutBlobFromURLCopySourceAuthNegative()
12281224
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
12291225
_require.NoError(err)
12301226

1231-
// Random seed for data generation
1232-
seed := int64(crc64.Checksum([]byte(testName), shared.CRC64Table))
1233-
random := rand.New(rand.NewSource(seed))
1234-
12351227
containerName := testcommon.GenerateContainerName(testName)
12361228
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
12371229
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
@@ -1242,7 +1234,7 @@ func (s *BlockBlobRecordedTestsSuite) TestPutBlobFromURLCopySourceAuthNegative()
12421234

12431235
// Upload some data to source
12441236
contentSize := 4 * 1024 // 4KB
1245-
r, _ := testcommon.GetDataAndReader(random, contentSize)
1237+
r, _ := testcommon.GetDataAndReader(testName, contentSize)
12461238
_, err = srcBBClient.Upload(context.Background(), streaming.NopCloser(r), nil)
12471239
_require.Nil(err)
12481240

@@ -1977,7 +1969,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestSetTierOnCopyBlockBlobFromURL() {
19771969
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
19781970

19791971
const contentSize = 4 * 1024 * 1024 // 4 MB
1980-
contentReader, _ := testcommon.GetRandomDataAndReader(contentSize)
1972+
contentReader, _ := testcommon.GetDataAndReader(testName, contentSize)
19811973

19821974
srcBlob := containerClient.NewBlockBlobClient(testcommon.GenerateBlobName(testName))
19831975

@@ -2748,7 +2740,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestCreateBlockBlobReturnsVID() {
27482740
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
27492741

27502742
testSize := 2 * 1024 * 1024 // 1MB
2751-
r, _ := testcommon.GetRandomDataAndReader(testSize)
2743+
r, _ := testcommon.GetDataAndReader(testName, testSize)
27522744
bbClient := containerClient.NewBlockBlobClient(testcommon.GenerateBlobName(testName))
27532745

27542746
// Prepare source blob for copy.

sdk/storage/azblob/internal/testcommon/common.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ package testcommon
1010
import (
1111
"bytes"
1212
"context"
13-
crypto_rand "crypto/rand"
1413
"encoding/base64"
1514
"encoding/binary"
1615
"errors"
1716
"fmt"
17+
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/shared"
18+
"hash/crc64"
1819
"io"
1920
"math/rand"
2021
"os"
@@ -82,15 +83,12 @@ func GetReaderToGeneratedBytes(n int) io.ReadSeekCloser {
8283
return streaming.NopCloser(r)
8384
}
8485

85-
func GetRandomDataAndReader(n int) (*bytes.Reader, []byte) {
86+
func GetDataAndReader(testName string, n int) (*bytes.Reader, []byte) {
87+
// Random seed for data generation
88+
seed := int64(crc64.Checksum([]byte(testName), shared.CRC64Table))
89+
random := rand.New(rand.NewSource(seed))
8690
data := make([]byte, n)
87-
_, _ = crypto_rand.Read(data)
88-
return bytes.NewReader(data), data
89-
}
90-
91-
func GetDataAndReader(r *rand.Rand, n int) (*bytes.Reader, []byte) {
92-
data := make([]byte, n)
93-
_, _ = r.Read(data)
91+
_, _ = random.Read(data)
9492
return bytes.NewReader(data), data
9593
}
9694

@@ -189,6 +187,7 @@ func GetRequiredEnv(name string) (string, error) {
189187
func BeforeTest(t *testing.T, suite string, test string) {
190188
const urlRegex = `https://\S+\.blob\.core\.windows\.net`
191189
const tokenRegex = `(?:Bearer\s).*`
190+
//const queryParamRegex = `=([^&|\n|\t\s]+)` // Note: Add query param name before this
192191
require.NoError(t, recording.AddURISanitizer(FakeStorageURL, urlRegex, nil))
193192
require.NoError(t, recording.AddHeaderRegexSanitizer("x-ms-copy-source", FakeStorageURL, urlRegex, nil))
194193
require.NoError(t, recording.AddHeaderRegexSanitizer("x-ms-copy-source-authorization", FakeToken, tokenRegex, nil))

sdk/storage/azblob/pageblob/client_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func (s *PageBlobUnrecordedTestsSuite) TestPutPagesWithAutoGeneratedCRC64() {
518518

519519
// put page with valid auto-generated CRC64
520520
contentSize := 1024
521-
readerToBody, body := testcommon.GetRandomDataAndReader(contentSize)
521+
readerToBody, body := testcommon.GetDataAndReader(testName, contentSize)
522522
offset, _, count := int64(0), int64(0)+int64(contentSize-1), int64(contentSize)
523523
crc64Value := crc64.Checksum(body, shared.CRC64Table)
524524
_ = body
@@ -540,7 +540,7 @@ func (s *PageBlobUnrecordedTestsSuite) TestPutPagesWithAutoGeneratedCRC64() {
540540
_require.Equal((*putResp.Date).IsZero(), false)
541541

542542
// put page with bad MD5
543-
readerToBody, _ = testcommon.GetRandomDataAndReader(1024)
543+
readerToBody, _ = testcommon.GetDataAndReader(testName, 1024)
544544
badCRC64 := rand.Uint64()
545545
putResp, err = pbClient.UploadPages(context.Background(), streaming.NopCloser(readerToBody), blob.HTTPRange{Offset: offset, Count: count}, &pageblob.UploadPagesOptions{
546546
TransactionalValidation: blob.TransferValidationTypeCRC64(badCRC64),
@@ -551,7 +551,7 @@ func (s *PageBlobUnrecordedTestsSuite) TestPutPagesWithAutoGeneratedCRC64() {
551551
}
552552

553553
// nolint
554-
func (s *PageBlobUnrecordedTestsSuite) TestPutPagesWithMD5() {
554+
func (s *PageBlobRecordedTestsSuite) TestPutPagesWithMD5() {
555555
_require := require.New(s.T())
556556
testName := s.T().Name()
557557
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
@@ -568,7 +568,7 @@ func (s *PageBlobUnrecordedTestsSuite) TestPutPagesWithMD5() {
568568

569569
// put page with valid MD5
570570
contentSize := 1024
571-
readerToBody, body := testcommon.GetRandomDataAndReader(contentSize)
571+
readerToBody, body := testcommon.GetDataAndReader(testName, contentSize)
572572
offset, _, count := int64(0), int64(0)+int64(contentSize-1), int64(contentSize)
573573
md5Value := md5.Sum(body)
574574
_ = body
@@ -591,8 +591,8 @@ func (s *PageBlobUnrecordedTestsSuite) TestPutPagesWithMD5() {
591591
_require.Equal((*putResp.Date).IsZero(), false)
592592

593593
// put page with bad MD5
594-
readerToBody, _ = testcommon.GetRandomDataAndReader(1024)
595-
_, badMD5 := testcommon.GetRandomDataAndReader(16)
594+
readerToBody, _ = testcommon.GetDataAndReader(testName, 1024)
595+
_, badMD5 := testcommon.GetDataAndReader(testName, 16)
596596
badContentMD5 := badMD5[:]
597597
putResp, err = pbClient.UploadPages(context.Background(), streaming.NopCloser(readerToBody), blob.HTTPRange{Offset: offset, Count: count}, &pageblob.UploadPagesOptions{
598598
TransactionalValidation: blob.TransferValidationTypeMD5(badContentMD5),

0 commit comments

Comments
 (0)