Skip to content

Commit c326b6e

Browse files
authored
Merge pull request #11208 from Grayer123/bugfix/testcoverage
Bug Fix: resolve resources test coverage #5216
2 parents c334b9b + da63fec commit c326b6e

File tree

8 files changed

+22706
-682
lines changed

8 files changed

+22706
-682
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
using Xunit.Abstractions;
18+
19+
namespace Microsoft.Azure.Commands.Resources.Test.ScenarioTests
20+
{
21+
public class InvokeResourceActionTests : ResourceTestRunner
22+
{
23+
public InvokeResourceActionTests(ITestOutputHelper output) : base(output)
24+
{
25+
}
26+
27+
[Fact]
28+
[Trait(Category.AcceptanceType, Category.CheckIn)]
29+
public void InvokeResourceActionsWithResouceId()
30+
{
31+
TestRunner.RunTestScript("Test-InvokeResourceActionsWithResouceId");
32+
}
33+
}
34+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Tests invoking registering resource provider action
18+
#>
19+
function Test-InvokeResourceActionsWithResouceId
20+
{
21+
# Setup
22+
$rpName = "Microsoft.ApiManagement"
23+
$action = "Register"
24+
$subId = GetDefaultSubscriptionId
25+
$resourceId = $subId + "/providers/" + $rpName
26+
Unregister-AzResourceProvider -ProviderNamespace $rpName
27+
28+
try
29+
{
30+
# Test
31+
$res = Invoke-AzResourceAction -ResourceId $resourceId -action $action -Force
32+
33+
34+
# Assert
35+
Assert-AreEqual $res.registrationState Registering
36+
37+
$statusChanged = $false
38+
39+
# within two minutes, the registrationState should change to "Registered"
40+
$timeout = new-timespan -Minutes 2
41+
$sw = [diagnostics.stopwatch]::StartNew()
42+
43+
while ($sw.elapsed -lt $timeout){
44+
$rp = Get-AzResourceProvider | where ProviderNamespace -eq $rpName
45+
if($rp -ne $null -and $rp.registrationState -eq "Registered") {
46+
$statusChanged = $true
47+
break
48+
}
49+
start-sleep -seconds 20
50+
}
51+
52+
Assert-True { $statusChanged }
53+
}
54+
finally
55+
{
56+
# Cleanup
57+
Unregister-AzResourceProvider -ProviderNamespace $rpName
58+
}
59+
}
60+
61+
<#
62+
.SYNOPSIS
63+
utility method to get default subscriptionId
64+
#>
65+
function GetDefaultSubscriptionId
66+
{
67+
$context = Get-AzContext
68+
$subId = "/subscriptions/" + $context.Subscription.Id
69+
70+
return $subId
71+
}

src/Resources/Resources.Test/ScenarioTests/ResourceGroupTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ public void TestNewDeploymentAndProviderRegistration()
109109
TestRunner.RunTestScript("Test-NewDeploymentAndProviderRegistration");
110110
}
111111

112-
[Fact(Skip = "Need service team to re-record test after changes to the ClientRuntime.")]
113-
[Trait("Re-record", "ClientRuntime changes")]
112+
[Fact]
114113
[Trait(Category.AcceptanceType, Category.CheckIn)]
115114
public void TestRemoveDeployment()
116115
{

src/Resources/Resources.Test/ScenarioTests/ResourceGroupTests.ps1

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,33 @@ function Test-NewDeploymentAndProviderRegistration
237237

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

249249
try
250250
{
251-
# Test
251+
# First create new resource group deployment
252252
New-AzResourceGroup -Name $rgName -Location "East US"
253253
$job = New-AzResourceGroupDeployment -ResourceGroupName $rgName -Name $deploymentName -TemplateUri $templateUri -AsJob
254254
Wait-Job $job
255255
$deployment = Receive-Job $job
256-
Assert-True { Remove-AzResourceGroupDeployment -ResourceGroupName $deployment.ResourceGroupName -Name $deployment.DeploymentName }
256+
257+
# Test
258+
$res = Remove-AzResourceGroupDeployment -ResourceGroupName $deployment.ResourceGroupName -Name $deployment.DeploymentName
259+
260+
# Assert
261+
Assert-True { $res }
262+
263+
# After deletion, try to get the given deployment should throw an error
264+
Get-AzResourceGroupDeployment -ResourceGroupName $rgName -Name $deploymentName -ErrorAction SilentlyContinue
265+
Assert-True { $Error[0] -like "*Deployment 'Test' could not be found." }
266+
$Error.Clear()
257267
}
258268
finally
259269
{

src/Resources/Resources.Test/ScenarioTests/ResourceTestRunner.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
using System.Linq;
1818
using System.Net.Http;
1919
using System.Net.Http.Headers;
20-
using System.Threading;
21-
using System.Threading.Tasks;
2220
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2321
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
2422
using Microsoft.Azure.Commands.TestFx;
@@ -52,16 +50,16 @@ protected ResourceTestRunner(ITestOutputHelper output)
5250
new ResourcesRecordMatcher(ignoreResourcesClient, resourceProviders, userAgentsToIgnore))
5351
.WithExtraUserAgentsToIgnore(new Dictionary<string, string>
5452
{
55-
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2016-07-01"},
53+
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2019-10-01"},
5654
})
5755
.WithMockContextAction(() =>
5856
{
5957
var credentials = HttpMockServer.Mode != HttpRecorderMode.Playback
6058
? new Func<ServiceClientCredentials>(() =>
61-
{
62-
var testEnvironment = TestEnvironmentFactory.GetTestEnvironment();
63-
return testEnvironment.TokenInfo[TokenAudience.Management];
64-
})()
59+
{
60+
var testEnvironment = TestEnvironmentFactory.GetTestEnvironment();
61+
return testEnvironment.TokenInfo[TokenAudience.Management];
62+
})()
6563
: new TokenCredentials("foo");
6664

6765
HttpClientHelperFactory.Instance = new TestHttpClientHelperFactory(credentials);

0 commit comments

Comments
 (0)