Skip to content

Commit de2bf7a

Browse files
Storage test infra refactor (Azure#24351)
* Initial test resource refactor * converted blob/datalake/share to new test infra * ported test infra to queues * minor refactor * CI sanity check * Fixed default client options generation for tests * fix incorrect service uri bug * fixed default test tenant for datalake tests * Fixed cred supplier for datalake tests * split some functionality to specific services ServiceCLient getters are now in package-specific extensions instead of on the client builder directly. Property rename. * cleanup * refactored disposing containers Co-authored-by: jschrepp-MSFT <[email protected]>
1 parent aaa6e05 commit de2bf7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1596
-1247
lines changed

sdk/storage/Azure.Storage.Blobs.Batch/tests/Azure.Storage.Blobs.Batch.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs" LinkBase="Shared\Core" />
2525
<Compile Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Blobs\tests\BlobTestBase.cs" LinkBase="Shared" />
2626
<Compile Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Blobs\tests\BlobTestEnvironment.cs" LinkBase="Shared" />
27+
<Compile Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Blobs\tests\ClientBuilderExtensions.cs" LinkBase="Shared" />
28+
<Compile Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Blobs\tests\DisposingContainer.cs" LinkBase="Shared" />
2729
<Compile Include="$(AzureStorageSharedSources)StorageConnectionString.cs" LinkBase="Shared" />
2830
<Compile Include="$(AzureStorageSharedSources)SharedAccessSignatureCredentials.cs" LinkBase="Shared" />
2931
<Compile Include="$(AzureStorageSharedSources)UriExtensions.cs" LinkBase="Shared" />

sdk/storage/Azure.Storage.Blobs.Batch/tests/BlobBatchClientTests.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Azure.Storage.Blobs.Batch.Tests;
1212
using Azure.Storage.Blobs.Models;
1313
using Azure.Storage.Blobs.Specialized;
14+
using Azure.Storage.Blobs.Tests;
1415
using Azure.Storage.Sas;
1516
using Azure.Storage.Test;
1617
using Azure.Storage.Test.Shared;
@@ -220,7 +221,7 @@ public async Task Batch_AzureSasCredential()
220221
// Create a container using SAS for Auth
221222
await using DisposingContainer test = await GetTestContainerAsync();
222223

223-
var serviceClient = GetServiceClient_SharedKey();
224+
var serviceClient = BlobsClientBuilder.GetServiceClient_SharedKey();
224225
var sas = GetAccountSasCredentials().SasToken;
225226
var sasServiceClient = InstrumentClient(new BlobServiceClient(serviceClient.Uri, new AzureSasCredential(sas), GetOptions()));
226227
await using TestScenario scenario = Scenario(sasServiceClient);
@@ -342,7 +343,7 @@ public async Task Delete_ContainerScoped_Basic_ContainerSas()
342343
{
343344
BlobContainerName = containerName
344345
};
345-
BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(GetNewSharedKeyCredentials());
346+
BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(Tenants.GetNewSharedKeyCredentials());
346347
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(scenario.Service.Uri)
347348
{
348349
BlobContainerName = containerName,
@@ -424,7 +425,7 @@ public async Task Delete_ContainerScoped_Basic_Convenience_ContainerSas()
424425
{
425426
BlobContainerName = containerName
426427
};
427-
BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(GetNewSharedKeyCredentials());
428+
BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(Tenants.GetNewSharedKeyCredentials());
428429
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(scenario.Service.Uri)
429430
{
430431
BlobContainerName = containerName,
@@ -581,9 +582,9 @@ public async Task Delete_MultipleFail_NoThrow()
581582
public async Task Delete_Error()
582583
{
583584
// Arrange
584-
BlobServiceClient service = GetServiceClient_SharedKey();
585+
BlobServiceClient service = BlobsClientBuilder.GetServiceClient_SharedKey();
585586
BlobServiceClient invalidServiceClient = InstrumentClient(new BlobServiceClient(
586-
GetServiceClient_SharedKey().Uri,
587+
BlobsClientBuilder.GetServiceClient_SharedKey().Uri,
587588
GetOptions()));
588589
BlobBatchClient blobBatchClient = invalidServiceClient.GetBlobBatchClient();
589590
using BlobBatch batch = blobBatchClient.CreateBatch();
@@ -702,7 +703,7 @@ public async Task SetBlobAccessTier_ContainerScoped_Basic_ContainerSas()
702703
{
703704
BlobContainerName = containerName
704705
};
705-
BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(GetNewSharedKeyCredentials());
706+
BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(Tenants.GetNewSharedKeyCredentials());
706707
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(scenario.Service.Uri)
707708
{
708709
BlobContainerName = containerName,
@@ -784,7 +785,7 @@ public async Task SetBlobAccessTier_ContainerScoped_Basic_Convenience_ContainerS
784785
{
785786
BlobContainerName = containerName
786787
};
787-
BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(GetNewSharedKeyCredentials());
788+
BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(Tenants.GetNewSharedKeyCredentials());
788789
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(scenario.Service.Uri)
789790
{
790791
BlobContainerName = containerName,
@@ -1018,9 +1019,9 @@ public async Task SetBlobAccessTier_Version()
10181019
public async Task SetBlobAccessTier_Error()
10191020
{
10201021
// Arrange
1021-
BlobServiceClient service = GetServiceClient_SharedKey();
1022+
BlobServiceClient service = BlobsClientBuilder.GetServiceClient_SharedKey();
10221023
BlobServiceClient invalidServiceClient = InstrumentClient(new BlobServiceClient(
1023-
GetServiceClient_SharedKey().Uri,
1024+
BlobsClientBuilder.GetServiceClient_SharedKey().Uri,
10241025
GetOptions()));
10251026
BlobBatchClient blobBatchClient = invalidServiceClient.GetBlobBatchClient();
10261027
using BlobBatch batch = blobBatchClient.CreateBatch();
@@ -1038,7 +1039,7 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
10381039
#endregion SetBlobAccessTier
10391040

10401041
#region Scenario helper
1041-
private TestScenario Scenario() => Scenario(GetServiceClient_SharedKey());
1042+
private TestScenario Scenario() => Scenario(BlobsClientBuilder.GetServiceClient_SharedKey());
10421043
private TestScenario Scenario(BlobServiceClient client) => new TestScenario(this, client);
10431044

10441045
/// <summary>

sdk/storage/Azure.Storage.Blobs/tests/AppendBlobClientTests.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Azure.Core.TestFramework;
1414
using Azure.Storage.Blobs.Models;
1515
using Azure.Storage.Blobs.Specialized;
16+
using Azure.Storage.Blobs.Tests;
1617
using Azure.Storage.Sas;
1718
using Azure.Storage.Shared;
1819
using Azure.Storage.Test;
@@ -78,11 +79,11 @@ public void Ctor_Uri()
7879
public void Ctor_TokenAuth_Http()
7980
{
8081
// Arrange
81-
Uri httpUri = new Uri(TestConfigOAuth.BlobServiceEndpoint).ToHttp();
82+
Uri httpUri = new Uri(Tenants.TestConfigOAuth.BlobServiceEndpoint).ToHttp();
8283

8384
// Act
8485
TestHelper.AssertExpectedException(
85-
() => new AppendBlobClient(httpUri, GetOAuthCredential()),
86+
() => new AppendBlobClient(httpUri, Tenants.GetOAuthCredential()),
8687
new ArgumentException("Cannot use TokenCredential without HTTPS."));
8788
}
8889

@@ -431,7 +432,7 @@ public async Task CreateAsync_EncryptionScopeAccountSAS()
431432
// Arrange
432433
string containerName = GetNewContainerName();
433434
await using DisposingContainer test = await GetTestContainerAsync(containerName: containerName);
434-
BlobServiceClient blobServiceClient = GetServiceClient_SharedKey();
435+
BlobServiceClient blobServiceClient = BlobsClientBuilder.GetServiceClient_SharedKey();
435436

436437
AccountSasBuilder accountSasBuilder = new AccountSasBuilder(
437438
permissions: AccountSasPermissions.All,
@@ -457,7 +458,7 @@ public async Task CreateAsync_EncryptionScopeAccountSAS()
457458
public async Task CreateAsync_EncryptionScopeIdentitySAS()
458459
{
459460
// Arrange
460-
BlobServiceClient oauthService = GetServiceClient_OauthAccount();
461+
BlobServiceClient oauthService = BlobsClientBuilder.GetServiceClient_OAuth();
461462
await using DisposingContainer test = await GetTestContainerAsync(oauthService);
462463

463464
Response<UserDelegationKey> userDelegationKey = await oauthService.GetUserDelegationKeyAsync(
@@ -478,7 +479,7 @@ public async Task CreateAsync_EncryptionScopeIdentitySAS()
478479
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(test.Container.Uri)
479480
{
480481
BlobName = blobName,
481-
Sas = blobSasBuilder.ToSasQueryParameters(userDelegationKey.Value, TestConfigOAuth.AccountName)
482+
Sas = blobSasBuilder.ToSasQueryParameters(userDelegationKey.Value, Tenants.TestConfigOAuth.AccountName)
482483
};
483484
AppendBlobClient sasBlob = InstrumentClient(new AppendBlobClient(blobUriBuilder.ToUri(), GetOptions()));
484485

@@ -502,7 +503,7 @@ public async Task CreateAsync_Headers()
502503
public async Task CreateAsync_Error()
503504
{
504505
// Arrange
505-
BlobServiceClient blobService = GetServiceClient_SharedKey();
506+
BlobServiceClient blobService = BlobsClientBuilder.GetServiceClient_SharedKey();
506507
BlobContainerClient containerClient = InstrumentClient(blobService.GetBlobContainerClient(GetNewContainerName()));
507508
AppendBlobClient blob = InstrumentClient(containerClient.GetAppendBlobClient(GetNewBlobName()));
508509

@@ -688,7 +689,7 @@ public async Task CreateIfNotExistsAsync_Exists()
688689
public async Task CreateIfNotExistsAsync_Error()
689690
{
690691
// Arrange
691-
BlobServiceClient serviceClient = GetServiceClient_SharedKey();
692+
BlobServiceClient serviceClient = BlobsClientBuilder.GetServiceClient_SharedKey();
692693
BlobContainerClient containerClient = InstrumentClient(serviceClient.GetBlobContainerClient(GetNewContainerName()));
693694
AppendBlobClient blob = InstrumentClient(containerClient.GetAppendBlobClient(GetNewBlobName()));
694695

@@ -1588,7 +1589,7 @@ await destBlob.AppendBlockFromUriAsync(
15881589
public async Task AppendBlockFromUriAsync_SourceBearerToken()
15891590
{
15901591
// Arrange
1591-
BlobServiceClient serviceClient = GetServiceClient_OauthAccount();
1592+
BlobServiceClient serviceClient = BlobsClientBuilder.GetServiceClient_OAuth();
15921593
await using DisposingContainer test = await GetTestContainerAsync(
15931594
service: serviceClient,
15941595
publicAccessType: PublicAccessType.None);
@@ -1623,7 +1624,7 @@ public async Task AppendBlockFromUriAsync_SourceBearerToken()
16231624
public async Task AppendBlockFromUriAsync_SourceBearerTokenFail()
16241625
{
16251626
// Arrange
1626-
BlobServiceClient serviceClient = GetServiceClient_OauthAccount();
1627+
BlobServiceClient serviceClient = BlobsClientBuilder.GetServiceClient_OAuth();
16271628
await using DisposingContainer test = await GetTestContainerAsync(
16281629
service: serviceClient,
16291630
publicAccessType: PublicAccessType.None);
@@ -2006,7 +2007,7 @@ public async Task OpenWriteAsync_AlternatingWriteAndFlush()
20062007
public async Task OpenWriteAsync_Error()
20072008
{
20082009
// Arrange
2009-
BlobServiceClient service = GetServiceClient_SharedKey();
2010+
BlobServiceClient service = BlobsClientBuilder.GetServiceClient_SharedKey();
20102011
BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName()));
20112012
AppendBlobClient blob = InstrumentClient(container.GetAppendBlobClient(GetNewBlobName()));
20122013

@@ -2248,9 +2249,9 @@ public void CanMockClientConstructors()
22482249
var mock = new Mock<AppendBlobClient>(TestConfigDefault.ConnectionString, "name", "name", new BlobClientOptions()).Object;
22492250
mock = new Mock<AppendBlobClient>(TestConfigDefault.ConnectionString, "name", "name").Object;
22502251
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), new BlobClientOptions()).Object;
2251-
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), GetNewSharedKeyCredentials(), new BlobClientOptions()).Object;
2252+
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), Tenants.GetNewSharedKeyCredentials(), new BlobClientOptions()).Object;
22522253
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), new AzureSasCredential("foo"), new BlobClientOptions()).Object;
2253-
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), GetOAuthCredential(TestConfigHierarchicalNamespace), new BlobClientOptions()).Object;
2254+
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), Tenants.GetOAuthCredential(Tenants.TestConfigHierarchicalNamespace), new BlobClientOptions()).Object;
22542255
}
22552256

22562257
private AppendBlobRequestConditions BuildDestinationAccessConditions(

0 commit comments

Comments
 (0)