From 69689671e4156c98dd826764196c77820f2d8f70 Mon Sep 17 00:00:00 2001 From: jolov Date: Sun, 3 Mar 2024 08:29:31 -0800 Subject: [PATCH 1/5] save --- .../Redesign/AddDeleteAfterTagPolicy.cs | 2 ++ .../Redesign/InheritanceCheckTests.cs | 2 ++ .../Redesign/ManagementMockingPatternTests.cs | 2 ++ .../Redesign/ManagementRecordedTestBase.cs | 2 ++ .../Redesign/MockTestEnvironment.cs | 2 ++ .../Redesign/ResponseNullFilterPolicy.cs | 2 ++ .../src/Shared/TestClient.cs | 2 ++ .../src/storage/StorageAccount.cs | 2 +- .../tests/Azure.Provisioning.Tests.csproj | 11 +++++----- .../tests/ProvisioningTestEnvironment.cs | 11 ++++++++++ .../tests/ProvisioningTests.cs | 22 ++++++++++++------- 11 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/ProvisioningTestEnvironment.cs diff --git a/common/ManagementTestShared/Redesign/AddDeleteAfterTagPolicy.cs b/common/ManagementTestShared/Redesign/AddDeleteAfterTagPolicy.cs index 2bb784ce6be1b..de90854531c7b 100644 --- a/common/ManagementTestShared/Redesign/AddDeleteAfterTagPolicy.cs +++ b/common/ManagementTestShared/Redesign/AddDeleteAfterTagPolicy.cs @@ -10,6 +10,8 @@ using System.Text.Json; using System.Text.RegularExpressions; +#nullable disable + namespace Azure.ResourceManager.TestFramework { public class AddDeleteAfterTagPolicy : HttpPipelineSynchronousPolicy diff --git a/common/ManagementTestShared/Redesign/InheritanceCheckTests.cs b/common/ManagementTestShared/Redesign/InheritanceCheckTests.cs index f694b15b64ca5..f0f5bf6d02008 100644 --- a/common/ManagementTestShared/Redesign/InheritanceCheckTests.cs +++ b/common/ManagementTestShared/Redesign/InheritanceCheckTests.cs @@ -7,6 +7,8 @@ using System.Linq; using System.Reflection; +#nullable disable + namespace Azure.ResourceManager.TestFramework { public partial class InheritanceCheckTests diff --git a/common/ManagementTestShared/Redesign/ManagementMockingPatternTests.cs b/common/ManagementTestShared/Redesign/ManagementMockingPatternTests.cs index 16a918130d4a7..2508d5c3441c3 100644 --- a/common/ManagementTestShared/Redesign/ManagementMockingPatternTests.cs +++ b/common/ManagementTestShared/Redesign/ManagementMockingPatternTests.cs @@ -13,6 +13,8 @@ using System.Runtime.CompilerServices; using System.Threading.Tasks; +#nullable disable + namespace Azure.ResourceManager.TestFramework { public sealed class ManagementMockingPatternTests diff --git a/common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs b/common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs index fd41f5c64a2fa..595fa61d08660 100644 --- a/common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs +++ b/common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs @@ -13,6 +13,8 @@ using System.Reflection; using System.Threading.Tasks; +#nullable disable + namespace Azure.ResourceManager.TestFramework { public abstract class ManagementRecordedTestBase : RecordedTestBase diff --git a/common/ManagementTestShared/Redesign/MockTestEnvironment.cs b/common/ManagementTestShared/Redesign/MockTestEnvironment.cs index 30940a0ce2d61..32c8c993da543 100644 --- a/common/ManagementTestShared/Redesign/MockTestEnvironment.cs +++ b/common/ManagementTestShared/Redesign/MockTestEnvironment.cs @@ -5,6 +5,8 @@ using Azure.Core.TestFramework; using System; +#nullable disable + namespace Azure.ResourceManager.TestFramework { public class MockTestEnvironment : TestEnvironment diff --git a/common/ManagementTestShared/Redesign/ResponseNullFilterPolicy.cs b/common/ManagementTestShared/Redesign/ResponseNullFilterPolicy.cs index 308b13cbf3318..8d72b23ad97fb 100644 --- a/common/ManagementTestShared/Redesign/ResponseNullFilterPolicy.cs +++ b/common/ManagementTestShared/Redesign/ResponseNullFilterPolicy.cs @@ -7,6 +7,8 @@ using System.Text.Json; using System.Text.RegularExpressions; +#nullable disable + namespace Azure.ResourceManager.TestFramework { public class ResponseNullFilterPolicy : HttpPipelineSynchronousPolicy diff --git a/sdk/core/Azure.Core.TestFramework/src/Shared/TestClient.cs b/sdk/core/Azure.Core.TestFramework/src/Shared/TestClient.cs index 4d29b1715fd11..c20de1d9de0da 100644 --- a/sdk/core/Azure.Core.TestFramework/src/Shared/TestClient.cs +++ b/sdk/core/Azure.Core.TestFramework/src/Shared/TestClient.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +#nullable disable + using System; using System.Threading; using System.Threading.Tasks; diff --git a/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs b/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs index 9a71f73a7e045..8b52215a7786e 100644 --- a/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs +++ b/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs @@ -33,7 +33,7 @@ public StorageAccount(IConstruct scope, StorageKind kind, StorageSkuName sku, Re sku: new StorageSku(sku), kind: kind, // access tier cannot be set for premium accounts - accessTier: sku != StorageSkuName.PremiumLrs && sku != StorageSkuName.PremiumZrs ? StorageAccountAccessTier.Hot : null)) + accessTier: kind == StorageKind.BlobStorage || kind == StorageKind.StorageV2 ? StorageAccountAccessTier.Hot : null)) { AssignProperty(data => data.Name, GetAzureName(scope, name)); } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Azure.Provisioning.Tests.csproj b/sdk/provisioning/Azure.Provisioning/tests/Azure.Provisioning.Tests.csproj index 961469ea67ecb..014275f8ab5d6 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Azure.Provisioning.Tests.csproj +++ b/sdk/provisioning/Azure.Provisioning/tests/Azure.Provisioning.Tests.csproj @@ -3,18 +3,17 @@ $(RequiredTargetFrameworks) enable + true + true - - - - + + - - + diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTestEnvironment.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTestEnvironment.cs new file mode 100644 index 0000000000000..2cf431aad539c --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTestEnvironment.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; + +namespace Azure.Provisioning.Tests +{ + public class ProvisioningTestEnvironment : TestEnvironment + { + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index 23ea24279dbdb..6b05baebc15d5 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -24,11 +24,17 @@ using Azure.ResourceManager.Resources; using Azure.ResourceManager.Resources.Models; using Azure.ResourceManager.Storage.Models; +using Azure.ResourceManager.TestFramework; +using CoreTestEnvironment = Azure.Core.TestFramework.TestEnvironment; namespace Azure.Provisioning.Tests { - public class ProvisioningTests + public class ProvisioningTests : ManagementRecordedTestBase { + public ProvisioningTests() : base(isAsync: true) + { + } + private static readonly string _infrastructureRoot = Path.Combine(GetGitRoot(), "sdk", "provisioning", "Azure.Provisioning", "tests", "Infrastructure"); [Test] @@ -405,22 +411,22 @@ public async Task OutputsSpanningModules() public async Task ValidateBicepAsync(BinaryData? parameters = null, bool interactiveMode = false) { - if (TestEnvironment.GlobalIsRunningInCI) - { - return; - } + // if (CoreTestEnvironment.GlobalIsRunningInCI) + // { + // return; + // } var testPath = Path.Combine(_infrastructureRoot, TestContext.CurrentContext.Test.Name); - var client = new ArmClient(new DefaultAzureCredential()); + var client = GetArmClient(); ResourceGroupResource? rg = null; - SubscriptionResource subscription = await client.GetSubscriptions().GetAsync(Environment.GetEnvironmentVariable("SUBSCRIPTION_ID")); + SubscriptionResource subscription = await client.GetSubscriptions().GetAsync(Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID")); try { var bicepPath = Path.Combine(testPath, "main.bicep"); var args = Path.Combine( - TestEnvironment.RepositoryRoot, + CoreTestEnvironment.RepositoryRoot, "eng", "scripts", $"Validate-Bicep.ps1 {bicepPath}"); From 393fc0a374e7336dfea2cc41fd61606172be9b48 Mon Sep 17 00:00:00 2001 From: jolov Date: Sun, 3 Mar 2024 14:33:49 -0800 Subject: [PATCH 2/5] integrate with test framework --- .../src/TestEnvironment.cs | 2 +- .../Azure.Provisioning/assets.json | 4 ++ .../tests/ProvisioningTests.cs | 45 ++++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/assets.json diff --git a/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs b/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs index 2d8606da5fd88..cde5e119a219b 100644 --- a/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs +++ b/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs @@ -206,7 +206,7 @@ public virtual TokenCredential Credential } else { - var clientSecret = ClientSecret; + var clientSecret = GetOptionalVariable("CLIENT_SECRET"); if (string.IsNullOrWhiteSpace(clientSecret)) { _credential = new DefaultAzureCredential( diff --git a/sdk/provisioning/Azure.Provisioning/assets.json b/sdk/provisioning/Azure.Provisioning/assets.json new file mode 100644 index 0000000000000..97c7ac31baaab --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/assets.json @@ -0,0 +1,4 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "net" +} \ No newline at end of file diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index f802bf37d180f..bdc2b3f1fdab2 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -29,15 +29,16 @@ namespace Azure.Provisioning.Tests { + [AsyncOnly] public class ProvisioningTests : ManagementRecordedTestBase { - public ProvisioningTests() : base(isAsync: true) + public ProvisioningTests(bool async) : base(async) { } private static readonly string _infrastructureRoot = Path.Combine(GetGitRoot(), "sdk", "provisioning", "Azure.Provisioning", "tests", "Infrastructure"); - [Test] + [RecordedTest] public async Task WebSiteUsingL1() { var infra = new TestInfrastructure(); @@ -112,7 +113,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( })); } - [Test] + [RecordedTest] public async Task ResourceGroupOnly() { TestInfrastructure infrastructure = new TestInfrastructure(); @@ -122,7 +123,7 @@ public async Task ResourceGroupOnly() await ValidateBicepAsync(); } - [Test] + [RecordedTest] public async Task SqlServerUsingAdminPassword() { TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); @@ -144,7 +145,7 @@ await ValidateBicepAsync( interactiveMode: true); } - [Test] + [RecordedTest] public async Task SqlServerUsingIdentity() { TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); @@ -171,7 +172,7 @@ await ValidateBicepAsync( interactiveMode: true); } - [Test] + [RecordedTest] public async Task SqlServerUsingHybrid() { TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); @@ -203,7 +204,7 @@ await ValidateBicepAsync( interactiveMode: true); } - [Test] + [RecordedTest] public async Task WebSiteUsingL2() { var infra = new TestInfrastructure(); @@ -225,7 +226,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( })); } - [Test] + [RecordedTest] public async Task WebSiteUsingL3() { var infra = new TestInfrastructure(); @@ -249,7 +250,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( })); } - [Test] + [RecordedTest] public async Task WebSiteUsingL3SpecificSubscription() { var infra = new TestInfrastructure(); @@ -272,7 +273,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( })); } - [Test] + [RecordedTest] public async Task WebSiteUsingL3ResourceGroupScope() { var infra = new TestInfrastructure(scope: ConstructScope.ResourceGroup, configuration: new Configuration { UseInteractiveMode = true }); @@ -297,7 +298,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( }), interactiveMode: true); } - [Test] + [RecordedTest] public async Task StorageBlobDefaults() { var infra = new TestInfrastructure(); @@ -308,7 +309,7 @@ public async Task StorageBlobDefaults() await ValidateBicepAsync(); } - [Test] + [RecordedTest] public async Task RoleAssignmentWithParameter() { var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); @@ -322,7 +323,7 @@ public async Task RoleAssignmentWithParameter() await ValidateBicepAsync(BinaryData.FromObjectAsJson(new { principalId = new { value = Guid.Empty }}), interactiveMode: true); } - [Test] + [RecordedTest] public async Task RoleAssignmentWithoutParameter() { var infra = new TestInfrastructure(); @@ -336,7 +337,7 @@ public async Task RoleAssignmentWithoutParameter() await ValidateBicepAsync(); } - [Test] + [RecordedTest] public async Task RoleAssignmentWithoutParameterInteractiveMode() { var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); @@ -350,7 +351,7 @@ public async Task RoleAssignmentWithoutParameterInteractiveMode() await ValidateBicepAsync(interactiveMode: true); } - [Test] + [RecordedTest] public void RoleAssignmentPrincipalMustBeSuppliedInNonInteractiveMode() { var infra = new TestInfrastructure(); @@ -360,7 +361,7 @@ public void RoleAssignmentPrincipalMustBeSuppliedInNonInteractiveMode() Assert.Throws(() => storageAccount.AssignRole(RoleDefinition.StorageBlobDataContributor)); } - [Test] + [RecordedTest] public async Task StorageBlobDefaultsInPromptMode() { var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); @@ -371,7 +372,7 @@ public async Task StorageBlobDefaultsInPromptMode() await ValidateBicepAsync(interactiveMode: true); } - [Test] + [RecordedTest] public async Task CanAddCustomLocationParameterInInteractiveMode() { var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); @@ -388,7 +389,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( interactiveMode: true); } - [Test] + [RecordedTest] public async Task CanAssignParameterToMultipleResources() { var infra = new TestInfrastructure(); @@ -418,7 +419,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( })); } - [Test] + [RecordedTest] public async Task StorageBlobDropDown() { var infra = new TestInfrastructure(); @@ -433,7 +434,7 @@ public async Task StorageBlobDropDown() await ValidateBicepAsync(); } - [Test] + [RecordedTest] public async Task AppConfiguration() { var infra = new TestInfrastructure(); @@ -443,7 +444,7 @@ public async Task AppConfiguration() await ValidateBicepAsync(); } - [Test] + [RecordedTest] public void MultipleSubscriptions() { // ensure deterministic subscription names and directories @@ -459,7 +460,7 @@ public void MultipleSubscriptions() // await ValidateBicepAsync(); } - [Test] + [RecordedTest] public async Task OutputsSpanningModules() { var infra = new TestInfrastructure(); From 2a510781db08e0a69c94658ed004522eb4ac1730 Mon Sep 17 00:00:00 2001 From: jolov Date: Sun, 3 Mar 2024 14:40:11 -0800 Subject: [PATCH 3/5] remove env var --- .../Azure.Provisioning/tests/ProvisioningTests.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index bdc2b3f1fdab2..83d10ef84a191 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -494,16 +494,11 @@ public async Task OutputsSpanningModules() public async Task ValidateBicepAsync(BinaryData? parameters = null, bool interactiveMode = false) { - // if (CoreTestEnvironment.GlobalIsRunningInCI) - // { - // return; - // } - var testPath = Path.Combine(_infrastructureRoot, TestContext.CurrentContext.Test.Name); var client = GetArmClient(); ResourceGroupResource? rg = null; - SubscriptionResource subscription = await client.GetSubscriptions().GetAsync(Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID")); + SubscriptionResource subscription = await client.GetSubscriptions().GetAsync(TestEnvironment.SubscriptionId); try { From e686da9e57f4b7bfa9895b2c8d2b2d2e033056dc Mon Sep 17 00:00:00 2001 From: jolov Date: Sun, 3 Mar 2024 15:24:16 -0800 Subject: [PATCH 4/5] assets --- sdk/provisioning/Azure.Provisioning/assets.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/provisioning/Azure.Provisioning/assets.json b/sdk/provisioning/Azure.Provisioning/assets.json index 97c7ac31baaab..959e1dddc646b 100644 --- a/sdk/provisioning/Azure.Provisioning/assets.json +++ b/sdk/provisioning/Azure.Provisioning/assets.json @@ -1,4 +1,6 @@ { "AssetsRepo": "Azure/azure-sdk-assets", - "AssetsRepoPrefixPath": "net" + "AssetsRepoPrefixPath": "net", + "TagPrefix": "net/provisioning/Azure.Provisioning", + "Tag": "net/provisioning/Azure.Provisioning_bd30657e9a" } \ No newline at end of file From 8435dc356e1577ee38e858066f0cbf8be25c5fe5 Mon Sep 17 00:00:00 2001 From: jolov Date: Mon, 4 Mar 2024 08:13:07 -0800 Subject: [PATCH 5/5] Disable in CI for now --- .../Azure.Provisioning/tests/ProvisioningTests.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index 83d10ef84a191..8c2d91ab0b1bc 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -494,6 +494,11 @@ public async Task OutputsSpanningModules() public async Task ValidateBicepAsync(BinaryData? parameters = null, bool interactiveMode = false) { + if (CoreTestEnvironment.GlobalIsRunningInCI) + { + return; + } + var testPath = Path.Combine(_infrastructureRoot, TestContext.CurrentContext.Test.Name); var client = GetArmClient(); ResourceGroupResource? rg = null;