Skip to content

Bug Fix: resolve resources test coverage #5216 #11208

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

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,34 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.Resources.Test.ScenarioTests
{
public class InvokeResourceActionTests : ResourceTestRunner
{
public InvokeResourceActionTests(ITestOutputHelper output) : base(output)
{
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void InvokeResourceActionsWithResouceId()
{
TestRunner.RunTestScript("Test-InvokeResourceActionsWithResouceId");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests invoking registering resource provider action
#>
function Test-InvokeResourceActionsWithResouceId
{
# Setup
$rpName = "Microsoft.ApiManagement"
$action = "Register"
$subId = GetDefaultSubscriptionId
$resourceId = $subId + "/providers/" + $rpName
Unregister-AzResourceProvider -ProviderNamespace $rpName

try
{
# Test
$res = Invoke-AzResourceAction -ResourceId $resourceId -action $action -Force


# Assert
Assert-AreEqual $res.registrationState Registering

$statusChanged = $false

# within two minutes, the registrationState should change to "Registered"
$timeout = new-timespan -Minutes 2
$sw = [diagnostics.stopwatch]::StartNew()

while ($sw.elapsed -lt $timeout){
$rp = Get-AzResourceProvider | where ProviderNamespace -eq $rpName
if($rp -ne $null -and $rp.registrationState -eq "Registered") {
$statusChanged = $true
break
}
start-sleep -seconds 20
}

Assert-True { $statusChanged }
}
finally
{
# Cleanup
Unregister-AzResourceProvider -ProviderNamespace $rpName
}
}

<#
.SYNOPSIS
utility method to get default subscriptionId
#>
function GetDefaultSubscriptionId
{
$context = Get-AzContext
$subId = "/subscriptions/" + $context.Subscription.Id

return $subId
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ public void TestNewDeploymentAndProviderRegistration()
TestRunner.RunTestScript("Test-NewDeploymentAndProviderRegistration");
}

[Fact(Skip = "Need service team to re-record test after changes to the ClientRuntime.")]
[Trait("Re-record", "ClientRuntime changes")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestRemoveDeployment()
{
Expand Down
18 changes: 14 additions & 4 deletions src/Resources/Resources.Test/ScenarioTests/ResourceGroupTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,33 @@ function Test-NewDeploymentAndProviderRegistration

<#
.SYNOPSIS
Tests deployment delete is successful
Tests delete resource group deployment
#>
function Test-RemoveDeployment
{
# Setup
$deploymentName = "Test"
$templateUri = "https://gallery.azure.com/artifact/20140901/Microsoft.ResourceGroup.1.0.0/DeploymentTemplates/Template.json"
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json"
$rgName = "TestSDK0123"

try
{
# Test
# First create new resource group deployment
New-AzResourceGroup -Name $rgName -Location "East US"
$job = New-AzResourceGroupDeployment -ResourceGroupName $rgName -Name $deploymentName -TemplateUri $templateUri -AsJob
Wait-Job $job
$deployment = Receive-Job $job
Assert-True { Remove-AzResourceGroupDeployment -ResourceGroupName $deployment.ResourceGroupName -Name $deployment.DeploymentName }

# Test
$res = Remove-AzResourceGroupDeployment -ResourceGroupName $deployment.ResourceGroupName -Name $deployment.DeploymentName

# Assert
Assert-True { $res }

# After deletion, try to get the given deployment should throw an error
Get-AzResourceGroupDeployment -ResourceGroupName $rgName -Name $deploymentName -ErrorAction SilentlyContinue
Assert-True { $Error[0] -like "*Deployment 'Test' could not be found." }
$Error.Clear()
}
finally
{
Expand Down
12 changes: 5 additions & 7 deletions src/Resources/Resources.Test/ScenarioTests/ResourceTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Microsoft.Azure.Commands.TestFx;
Expand Down Expand Up @@ -52,16 +50,16 @@ protected ResourceTestRunner(ITestOutputHelper output)
new ResourcesRecordMatcher(ignoreResourcesClient, resourceProviders, userAgentsToIgnore))
.WithExtraUserAgentsToIgnore(new Dictionary<string, string>
{
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2016-07-01"},
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2019-10-01"},
})
.WithMockContextAction(() =>
{
var credentials = HttpMockServer.Mode != HttpRecorderMode.Playback
? new Func<ServiceClientCredentials>(() =>
{
var testEnvironment = TestEnvironmentFactory.GetTestEnvironment();
return testEnvironment.TokenInfo[TokenAudience.Management];
})()
{
var testEnvironment = TestEnvironmentFactory.GetTestEnvironment();
return testEnvironment.TokenInfo[TokenAudience.Management];
})()
: new TokenCredentials("foo");

HttpClientHelperFactory.Instance = new TestHttpClientHelperFactory(credentials);
Expand Down
Loading