Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with test framework #42343

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Text.Json;
using System.Text.RegularExpressions;

#nullable disable
JoshLove-msft marked this conversation as resolved.
Show resolved Hide resolved

namespace Azure.ResourceManager.TestFramework
{
public class AddDeleteAfterTagPolicy : HttpPipelineSynchronousPolicy
Expand Down
2 changes: 2 additions & 0 deletions common/ManagementTestShared/Redesign/InheritanceCheckTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Linq;
using System.Reflection;

#nullable disable

namespace Azure.ResourceManager.TestFramework
{
public partial class InheritanceCheckTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

#nullable disable

namespace Azure.ResourceManager.TestFramework
{
public sealed class ManagementMockingPatternTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using System.Reflection;
using System.Threading.Tasks;

#nullable disable

namespace Azure.ResourceManager.TestFramework
{
public abstract class ManagementRecordedTestBase<TEnvironment> : RecordedTestBase<TEnvironment>
Expand Down
2 changes: 2 additions & 0 deletions common/ManagementTestShared/Redesign/MockTestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Azure.Core.TestFramework;
using System;

#nullable disable

namespace Azure.ResourceManager.TestFramework
{
public class MockTestEnvironment : TestEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Text.Json;
using System.Text.RegularExpressions;

#nullable disable

namespace Azure.ResourceManager.TestFramework
{
public class ResponseNullFilterPolicy : HttpPipelineSynchronousPolicy
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/Shared/TestClient.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public virtual TokenCredential Credential
}
else
{
var clientSecret = ClientSecret;
var clientSecret = GetOptionalVariable("CLIENT_SECRET");
if (string.IsNullOrWhiteSpace(clientSecret))
{
_credential = new DefaultAzureCredential(
Expand Down
4 changes: 4 additions & 0 deletions sdk/provisioning/Azure.Provisioning/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
<PropertyGroup>
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<IsMgmtLibrary>true</IsMgmtLibrary>
<IncludeOperationsSharedSource>true</IncludeOperationsSharedSource>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<ProjectReference Include="..\..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj" />
<ProjectReference Include="..\src\Azure.Provisioning.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj" />
<ProjectReference Include="..\src\Azure.Provisioning.csproj" />
<Compile Include="$(TestFrameworkSupportFiles)" LinkBase="Shared\TestFramework" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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
{
}
}
62 changes: 32 additions & 30 deletions sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@
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
[AsyncOnly]
public class ProvisioningTests : ManagementRecordedTestBase<ProvisioningTestEnvironment>
{
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();
Expand Down Expand Up @@ -106,7 +113,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson(
}));
}

[Test]
[RecordedTest]
public async Task ResourceGroupOnly()
{
TestInfrastructure infrastructure = new TestInfrastructure();
Expand All @@ -116,7 +123,7 @@ public async Task ResourceGroupOnly()
await ValidateBicepAsync();
}

[Test]
[RecordedTest]
public async Task SqlServerUsingAdminPassword()
{
TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true });
Expand All @@ -138,7 +145,7 @@ await ValidateBicepAsync(
interactiveMode: true);
}

[Test]
[RecordedTest]
public async Task SqlServerUsingIdentity()
{
TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true });
Expand All @@ -165,7 +172,7 @@ await ValidateBicepAsync(
interactiveMode: true);
}

[Test]
[RecordedTest]
public async Task SqlServerUsingHybrid()
{
TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true });
Expand Down Expand Up @@ -197,7 +204,7 @@ await ValidateBicepAsync(
interactiveMode: true);
}

[Test]
[RecordedTest]
public async Task WebSiteUsingL2()
{
var infra = new TestInfrastructure();
Expand All @@ -219,7 +226,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson(
}));
}

[Test]
[RecordedTest]
public async Task WebSiteUsingL3()
{
var infra = new TestInfrastructure();
Expand All @@ -243,7 +250,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson(
}));
}

[Test]
[RecordedTest]
public async Task WebSiteUsingL3SpecificSubscription()
{
var infra = new TestInfrastructure();
Expand All @@ -266,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 });
Expand All @@ -291,7 +298,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson(
}), interactiveMode: true);
}

[Test]
[RecordedTest]
public async Task StorageBlobDefaults()
{
var infra = new TestInfrastructure();
Expand All @@ -302,7 +309,7 @@ public async Task StorageBlobDefaults()
await ValidateBicepAsync();
}

[Test]
[RecordedTest]
public async Task RoleAssignmentWithParameter()
{
var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true });
Expand All @@ -316,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();
Expand All @@ -330,7 +337,7 @@ public async Task RoleAssignmentWithoutParameter()
await ValidateBicepAsync();
}

[Test]
[RecordedTest]
public async Task RoleAssignmentWithoutParameterInteractiveMode()
{
var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true });
Expand All @@ -344,7 +351,7 @@ public async Task RoleAssignmentWithoutParameterInteractiveMode()
await ValidateBicepAsync(interactiveMode: true);
}

[Test]
[RecordedTest]
public void RoleAssignmentPrincipalMustBeSuppliedInNonInteractiveMode()
{
var infra = new TestInfrastructure();
Expand All @@ -354,7 +361,7 @@ public void RoleAssignmentPrincipalMustBeSuppliedInNonInteractiveMode()
Assert.Throws<InvalidOperationException>(() => storageAccount.AssignRole(RoleDefinition.StorageBlobDataContributor));
}

[Test]
[RecordedTest]
public async Task StorageBlobDefaultsInPromptMode()
{
var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true });
Expand All @@ -365,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 });
Expand All @@ -382,7 +389,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson(
interactiveMode: true);
}

[Test]
[RecordedTest]
public async Task CanAssignParameterToMultipleResources()
{
var infra = new TestInfrastructure();
Expand Down Expand Up @@ -412,7 +419,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson(
}));
}

[Test]
[RecordedTest]
public async Task StorageBlobDropDown()
{
var infra = new TestInfrastructure();
Expand All @@ -427,7 +434,7 @@ public async Task StorageBlobDropDown()
await ValidateBicepAsync();
}

[Test]
[RecordedTest]
public async Task AppConfiguration()
{
var infra = new TestInfrastructure();
Expand All @@ -437,7 +444,7 @@ public async Task AppConfiguration()
await ValidateBicepAsync();
}

[Test]
[RecordedTest]
public void MultipleSubscriptions()
{
// ensure deterministic subscription names and directories
Expand All @@ -453,7 +460,7 @@ public void MultipleSubscriptions()
// await ValidateBicepAsync();
}

[Test]
[RecordedTest]
public async Task OutputsSpanningModules()
{
var infra = new TestInfrastructure();
Expand Down Expand Up @@ -487,22 +494,17 @@ public async Task OutputsSpanningModules()

public async Task ValidateBicepAsync(BinaryData? parameters = null, bool interactiveMode = false)
{
if (TestEnvironment.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(TestEnvironment.SubscriptionId);

try
{
var bicepPath = Path.Combine(testPath, "main.bicep");
var args = Path.Combine(
TestEnvironment.RepositoryRoot,
CoreTestEnvironment.RepositoryRoot,
"eng",
"scripts",
$"Validate-Bicep.ps1 {bicepPath}");
Expand Down
Loading