Skip to content

Commit

Permalink
Fix storage management plane related tests (Azure#32778)
Browse files Browse the repository at this point in the history
* remove all the storage related recordings in media

* remove all the storage related recordings in batch

* add a small change in template to trigger core ci

* resolve comments
  • Loading branch information
Yao725 authored Dec 1, 2022
1 parent 27f151d commit 54f8d89
Show file tree
Hide file tree
Showing 186 changed files with 22,653 additions and 33,096 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Run `dotnet build /t:GenerateCode` to generate code.

``` yaml

azure-arm: true
csharp: true
library-name: ProviderShortName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading.Tasks;
using Azure.Core;
using Azure.Core.TestFramework;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Storage;
using Azure.ResourceManager.TestFramework;
using NUnit.Framework;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using Azure.ResourceManager.Batch.Models;
using Azure.ResourceManager.Storage.Models;
using Azure.ResourceManager.Batch.Tests.Helpers;
using NUnit.Framework;

namespace Azure.ResourceManager.Batch.Tests
{
public class BatchManagementTestBase : ManagementRecordedTestBase<BatchManagementTestEnvironment>
{
protected ArmClient Client { get; private set; }
protected ResourceGroupResource ResourceGroup { get; private set; }
protected ResourceIdentifier StorageAccountIdentifier { get; private set; }
protected AzureLocation DefaultLocation => AzureLocation.WestUS;
protected SubscriptionResource DefaultSubscription { get; private set; }

private ResourceIdentifier _resourceGroupIdentifier;

protected BatchManagementTestBase(bool isAsync, RecordedTestMode mode)
: base(isAsync, mode)
Expand All @@ -34,41 +32,69 @@ protected BatchManagementTestBase(bool isAsync)
}

[SetUp]
public async Task CreateCommonClient()
public void CreateCommonClient()
{
Client = GetArmClient();
DefaultSubscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false);
ResourceGroup = Client.GetResourceGroupResource(_resourceGroupIdentifier);
}

protected async Task<ResourceGroupResource> CreateResourceGroupAsync()
[OneTimeSetUp]
public async Task CommonGlobalSetup()
{
var resourceGroupName = Recording.GenerateAssetName("testRG-");
var rgOp = await DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(
WaitUntil.Completed,
resourceGroupName,
new ResourceGroupData(DefaultLocation)
var rgName = SessionRecording.GenerateAssetName("testrg-batch");
var storageAccountName = SessionRecording.GenerateAssetName("azstorageforbatch");
if (Mode == RecordedTestMode.Playback)
{
_resourceGroupIdentifier = ResourceGroupResource.CreateResourceIdentifier(SessionRecording.GetVariable("SUBSCRIPTION_ID", null), rgName);
StorageAccountIdentifier = StorageAccountResource.CreateResourceIdentifier(SessionRecording.GetVariable("SUBSCRIPTION_ID", null), rgName, storageAccountName);
}
else
{
using (SessionRecording.DisableRecording())
{
Tags =
{
{ "test", "env" }
}
});
return rgOp.Value;
var subscription = await GlobalClient.GetDefaultSubscriptionAsync();
var rgLro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(AzureLocation.WestUS2));
var storage = await CreateStorageAccount(rgLro.Value, storageAccountName);
_resourceGroupIdentifier = rgLro.Value.Data.Id;
StorageAccountIdentifier = storage.Id;
}
}
await StopSessionRecordingAsync();
}
#region GetStorageAccoountId
public async Task<StorageAccountCollection> GetStorageAccountCollectionAsync()

private async Task<StorageAccountResource> CreateStorageAccount(ResourceGroupResource rg, string storageAccountName)
{
var resourceGroup = await CreateResourceGroupAsync();
return resourceGroup.GetStorageAccounts();
var storageInput = ResourceDataHelper.GetStorageAccountData();
var lro = await rg.GetStorageAccounts().CreateOrUpdateAsync(WaitUntil.Completed, storageAccountName, storageInput);
return lro.Value;
}
public async Task<StorageAccountResource> GetStorageAccountResource()

protected async Task<BatchAccountResource> CreateBatchAccount(ResourceGroupResource rg, string batchAccountName, ResourceIdentifier storageAccountId)
{
var storageCollection = await GetStorageAccountCollectionAsync();
var storageName = Recording.GenerateAssetName("accountforbatch");
var storageInput = ResourceDataHelper.GetStorageAccountData();
var lros = await storageCollection.CreateOrUpdateAsync(WaitUntil.Completed, storageName, storageInput);
return lros.Value;
var input = ResourceDataHelper.GetBatchAccountData(storageAccountId);
var lro = await rg.GetBatchAccounts().CreateOrUpdateAsync(WaitUntil.Completed, batchAccountName, input);
return lro.Value;
}

protected async Task<BatchAccountPoolResource> CreateBatchAccountPool(BatchAccountResource batchAccount, string poolName)
{
var input = ResourceDataHelper.GetBatchAccountPoolData();
var lro = await batchAccount.GetBatchAccountPools().CreateOrUpdateAsync(WaitUntil.Completed, poolName, input);
return lro.Value;
}

protected async Task<BatchApplicationResource> CreateBatchApplication(BatchAccountResource batchAccount, string applicationName)
{
var input = ResourceDataHelper.GetBatchApplicationData();
var lro = await batchAccount.GetBatchApplications().CreateOrUpdateAsync(WaitUntil.Completed, applicationName, input);
return lro.Value;
}

protected async Task<BatchApplicationPackageResource> CreateBatchApplicationPackage(BatchApplicationResource batchApplication, string applicationPackageName)
{
var input = ResourceDataHelper.GetBatchApplicationPackageData();
var lro = await batchApplication.GetBatchApplicationPackages().CreateOrUpdateAsync(WaitUntil.Completed, applicationPackageName, input);
return lro.Value;
}
#endregion
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 54f8d89

Please sign in to comment.