@@ -20,8 +20,45 @@ import (
2020 "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/shared"
2121 "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/testcommon"
2222 "github.com/stretchr/testify/require"
23+ "github.com/stretchr/testify/suite"
2324)
2425
26+ var ctx = context .Background ()
27+
28+ type AZBlobRecordedTestsSuite struct {
29+ suite.Suite
30+ }
31+
32+ type AZBlobUnrecordedTestsSuite struct {
33+ suite.Suite
34+ }
35+
36+ // Hookup to the testing framework
37+ func Test (t * testing.T ) {
38+ suite .Run (t , & AZBlobRecordedTestsSuite {})
39+ //suite.Run(t, &AZBlobUnrecordedTestsSuite{})
40+ }
41+
42+ // nolint
43+ func (s * AZBlobRecordedTestsSuite ) BeforeTest (suite string , test string ) {
44+ testcommon .BeforeTest (s .T (), suite , test )
45+ }
46+
47+ // nolint
48+ func (s * AZBlobRecordedTestsSuite ) AfterTest (suite string , test string ) {
49+ testcommon .AfterTest (s .T (), suite , test )
50+ }
51+
52+ // nolint
53+ func (s * AZBlobUnrecordedTestsSuite ) BeforeTest (suite string , test string ) {
54+
55+ }
56+
57+ // nolint
58+ func (s * AZBlobUnrecordedTestsSuite ) AfterTest (suite string , test string ) {
59+
60+ }
61+
2562// create a test file
2663// nolint
2764func generateFile (fileName string , fileSize int ) []byte {
@@ -35,30 +72,33 @@ func generateFile(fileName string, fileSize int) []byte {
3572
3673// nolint
3774func performUploadStreamToBlockBlobTest (t * testing.T , _require * require.Assertions , testName string , blobSize , bufferSize , maxBuffers int ) {
38- svcClient , err := testcommon .GetServiceClient (t , testcommon .TestAccountDefault , nil )
75+ client , err := testcommon .GetClient (t , testcommon .TestAccountDefault , nil )
3976 _require .NoError (err )
4077
4178 containerName := testcommon .GenerateContainerName (testName )
42- containerClient := testcommon .CreateNewContainer (context .Background (), _require , containerName , svcClient )
43- defer testcommon .DeleteContainer (context .Background (), _require , containerClient )
79+ _ , err = client .CreateContainer (context .Background (), containerName , nil )
80+ _require .NoError (err )
81+ defer func () {
82+ _ , err := client .DeleteContainer (context .Background (), containerName , nil )
83+ _require .NoError (err )
84+ }()
4485
4586 // Set up test blob
4687 blobName := testcommon .GenerateBlobName (testName )
47- blobClient := testcommon .GetBlockBlobClient (blobName , containerClient )
4888
4989 // Create some data to test the upload stream
5090 blobContentReader , blobData := testcommon .GenerateData (blobSize )
5191
5292 // Perform UploadStream
53- _ , err = blobClient .UploadStream (ctx , blobContentReader ,
93+ _ , err = client .UploadStream (ctx , containerName , blobName , blobContentReader ,
5494 & blockblob.UploadStreamOptions {BufferSize : bufferSize , MaxBuffers : maxBuffers })
5595
5696 // Assert that upload was successful
5797 _require .Equal (err , nil )
5898 // _require.Equal(uploadResp.RawResponse.StatusCode, 201)
5999
60100 // Download the blob to verify
61- downloadResponse , err := blobClient .DownloadStream (ctx , nil )
101+ downloadResponse , err := client .DownloadStream (ctx , containerName , blobName , nil )
62102 _require .Nil (err )
63103
64104 // Assert that the content is correct
@@ -134,17 +174,22 @@ func performUploadAndDownloadFileTest(t *testing.T, _require *require.Assertions
134174 _ = os .Remove (name )
135175 }(fileName )
136176
137- svcClient , err := testcommon .GetServiceClient (t , testcommon .TestAccountDefault , nil )
177+ client , err := testcommon .GetClient (t , testcommon .TestAccountDefault , nil )
138178 _require .NoError (err )
139179
140- containerClient := testcommon .CreateNewContainer (context .Background (), _require , testcommon .GenerateContainerName (testName ), svcClient )
141- defer testcommon .DeleteContainer (context .Background (), _require , containerClient )
180+ containerName := testcommon .GenerateContainerName (testName )
181+ _ , err = client .CreateContainer (context .Background (), containerName , nil )
182+ _require .NoError (err )
183+ defer func () {
184+ _ , err := client .DeleteContainer (context .Background (), containerName , nil )
185+ _require .NoError (err )
186+ }()
142187
143188 // Set up test blob
144- bbClient := testcommon .GetBlockBlobClient ( testcommon . GenerateBlobName (testName ), containerClient )
189+ blobName := testcommon .GenerateBlobName (testName )
145190
146191 // Upload the file to a block blob
147- _ , err = bbClient .UploadFile (context .Background (), file ,
192+ _ , err = client .UploadFile (context .Background (), containerName , blobName , file ,
148193 & blockblob.UploadFileOptions {
149194 BlockSize : int64 (blockSize ),
150195 Parallelism : uint16 (parallelism ),
@@ -153,13 +198,13 @@ func performUploadAndDownloadFileTest(t *testing.T, _require *require.Assertions
153198 _require .Equal (bytesTransferred > 0 && bytesTransferred <= int64 (fileSize ), true )
154199 },
155200 })
156- _require .Equal (err , nil )
201+ _require .NoError (err )
157202 //_require.Equal(response.StatusCode, 201)
158203
159204 // Set up file to download the blob to
160205 destFileName := "BigFile-downloaded.bin"
161206 destFile , err := os .Create (destFileName )
162- _require .Equal (err , nil )
207+ _require .NoError (err )
163208 defer func (destFile * os.File ) {
164209 _ = destFile .Close ()
165210
@@ -170,7 +215,9 @@ func performUploadAndDownloadFileTest(t *testing.T, _require *require.Assertions
170215 }(destFileName )
171216
172217 // Perform download
173- _ , err = bbClient .BlobClient ().DownloadFile (context .Background (),
218+ _ , err = client .DownloadFile (context .Background (),
219+ containerName ,
220+ blobName ,
174221 destFile ,
175222 & blob.DownloadFileOptions {
176223 Count : int64 (downloadCount ),
@@ -184,7 +231,7 @@ func performUploadAndDownloadFileTest(t *testing.T, _require *require.Assertions
184231 })
185232
186233 // Assert download was successful
187- _require .Equal (err , nil )
234+ _require .NoError (err )
188235
189236 // Assert downloaded data is consistent
190237 var destBuffer []byte
@@ -292,16 +339,21 @@ func performUploadAndDownloadBufferTest(t *testing.T, _require *require.Assertio
292339 _ , bytesToUpload := testcommon .GenerateData (blobSize )
293340
294341 // Set up test container
295- svcClient , err := testcommon .GetServiceClient (t , testcommon .TestAccountDefault , nil )
342+ client , err := testcommon .GetClient (t , testcommon .TestAccountDefault , nil )
343+ _require .NoError (err )
344+ containerName := testcommon .GenerateContainerName (testName )
345+ _ , err = client .CreateContainer (context .Background (), containerName , nil )
296346 _require .NoError (err )
297- containerClient := testcommon .CreateNewContainer (context .Background (), _require , testcommon .GenerateContainerName (testName ), svcClient )
298- defer testcommon .DeleteContainer (context .Background (), _require , containerClient )
347+ defer func () {
348+ _ , err := client .DeleteContainer (context .Background (), containerName , nil )
349+ _require .NoError (err )
350+ }()
299351
300352 // Set up test blob
301- bbClient := testcommon .GetBlockBlobClient ( testcommon . GenerateBlobName (testName ), containerClient )
353+ blobName := testcommon .GenerateBlobName (testName )
302354
303355 // Pass the Context, stream, stream size, block blob URL, and options to StreamToBlockBlob
304- _ , err = bbClient .UploadBuffer (context .Background (), bytesToUpload ,
356+ _ , err = client .UploadBuffer (context .Background (), containerName , blobName , bytesToUpload ,
305357 & blockblob.UploadBufferOptions {
306358 BlockSize : int64 (blockSize ),
307359 Parallelism : uint16 (parallelism ),
@@ -322,7 +374,9 @@ func performUploadAndDownloadBufferTest(t *testing.T, _require *require.Assertio
322374 }
323375
324376 // Download the blob to a buffer
325- _ , err = bbClient .BlobClient ().DownloadBuffer (context .Background (),
377+ _ , err = client .DownloadBuffer (context .Background (),
378+ containerName ,
379+ blobName ,
326380 destBuffer , & blob.DownloadBufferOptions {
327381 Count : int64 (downloadCount ),
328382 Offset : int64 (downloadOffset ),
@@ -529,63 +583,3 @@ func (s *AZBlobUnrecordedTestsSuite) TestDoBatchTransferWithError() {
529583 mmf .isClosed = true
530584 time .Sleep (time .Second * 5 )
531585}
532-
533- // nolint
534- func (s * AZBlobUnrecordedTestsSuite ) TestUploadStreamToBlobProperties () {
535- _require := require .New (s .T ())
536- testName := s .T ().Name ()
537- svcClient , err := testcommon .GetServiceClient (s .T (), testcommon .TestAccountDefault , nil )
538- _require .NoError (err )
539-
540- blobSize := 1024
541- bufferSize := 8 * 1024
542- maxBuffers := 3
543-
544- containerName := testcommon .GenerateContainerName (testName )
545- containerClient := testcommon .CreateNewContainer (context .Background (), _require , containerName , svcClient )
546- defer testcommon .DeleteContainer (context .Background (), _require , containerClient )
547-
548- // Set up test blob
549- blobName := testcommon .GenerateBlobName (testName )
550- bbClient := testcommon .GetBlockBlobClient (blobName , containerClient )
551- _require .Nil (err )
552- // Create some data to test the upload stream
553- blobContentReader , blobData := testcommon .GenerateData (blobSize )
554-
555- // Perform UploadStream
556- _ , err = bbClient .UploadStream (ctx , blobContentReader ,
557- & blockblob.UploadStreamOptions {
558- BufferSize : bufferSize ,
559- MaxBuffers : maxBuffers ,
560- Metadata : testcommon .BasicMetadata ,
561- Tags : testcommon .BasicBlobTagsMap ,
562- HTTPHeaders : & testcommon .BasicHeaders ,
563- })
564-
565- // Assert that upload was successful
566- _require .Equal (err , nil )
567- // _require.Equal(uploadResp.RawResponse.StatusCode, 201)
568-
569- getPropertiesResp , err := bbClient .GetProperties (ctx , nil )
570- _require .NoError (err )
571- _require .EqualValues (getPropertiesResp .Metadata , testcommon .BasicMetadata )
572- _require .Equal (* getPropertiesResp .TagCount , int64 (len (testcommon .BasicBlobTagsMap )))
573- _require .Equal (blob .ParseHTTPHeaders (getPropertiesResp ), testcommon .BasicHeaders )
574-
575- getTagsResp , err := bbClient .GetTags (ctx , nil )
576- _require .NoError (err )
577- _require .Len (getTagsResp .BlobTagSet , 3 )
578- for _ , blobTag := range getTagsResp .BlobTagSet {
579- _require .Equal (testcommon .BasicBlobTagsMap [* blobTag .Key ], * blobTag .Value )
580- }
581-
582- // Download the blob to verify
583- downloadResponse , err := bbClient .DownloadStream (ctx , nil )
584- _require .NoError (err )
585-
586- // Assert that the content is correct
587- actualBlobData , err := io .ReadAll (downloadResponse .Body )
588- _require .NoError (err )
589- _require .Equal (len (actualBlobData ), blobSize )
590- _require .EqualValues (actualBlobData , blobData )
591- }
0 commit comments