Skip to content

Commit 57e1fdc

Browse files
author
Hovsep
committed
Merge pull request Azure#1030 from hovsepm/dev
[#104016000] Fixed Compute tests
2 parents 98c119a + 1950a42 commit 57e1fdc

File tree

14 files changed

+57
-29
lines changed

14 files changed

+57
-29
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/EnvironmentSetupHelper.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ public EnvironmentSetupHelper()
5858
rmprofile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
5959
rmprofile.Context = new AzureContext(new AzureSubscription(), new AzureAccount(), rmprofile.Environments["foo"], new AzureTenant());
6060
rmprofile.Context.Subscription.Environment = "foo";
61-
AzureRMCmdlet.DefaultProfile = rmprofile;
62-
AzureSession.DataStore = datastore;
61+
if (AzureRMCmdlet.DefaultProfile == null)
62+
{
63+
AzureRMCmdlet.DefaultProfile = rmprofile;
64+
}
6365
ProfileClient = new ProfileClient(profile);
6466

6567
// Ignore SSL errors
@@ -162,12 +164,18 @@ private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
162164
environment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectory] = currentEnvironment.Endpoints.AADAuthUri.AbsoluteUri;
163165
environment.Endpoints[AzureEnvironment.Endpoint.Gallery] = currentEnvironment.Endpoints.GalleryUri.AbsoluteUri;
164166
environment.Endpoints[AzureEnvironment.Endpoint.ServiceManagement] = currentEnvironment.BaseUri.AbsoluteUri;
167+
environment.Endpoints[AzureEnvironment.Endpoint.ResourceManager] = currentEnvironment.Endpoints.ResourceManagementUri.AbsoluteUri;
165168

166169
if (!ProfileClient.Profile.Environments.ContainsKey(testEnvironmentName))
167170
{
168171
ProfileClient.AddOrSetEnvironment(environment);
169172
}
170173

174+
if (!AzureRMCmdlet.DefaultProfile.Environments.ContainsKey(testEnvironmentName))
175+
{
176+
AzureRMCmdlet.DefaultProfile.Environments[testEnvironmentName] = environment;
177+
}
178+
171179
if (currentEnvironment.SubscriptionId != null)
172180
{
173181
testSubscription = new AzureSubscription()
@@ -199,6 +207,17 @@ private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
199207
ProfileClient.Profile.Subscriptions[testSubscription.Id] = testSubscription;
200208
ProfileClient.Profile.Accounts[testAccount.Id] = testAccount;
201209
ProfileClient.SetSubscriptionAsDefault(testSubscription.Name, testSubscription.Account);
210+
211+
var testTenant = new AzureTenant() { Id = Guid.NewGuid() };
212+
if (!string.IsNullOrEmpty(currentEnvironment.Tenant))
213+
{
214+
Guid tenant;
215+
if (Guid.TryParse(currentEnvironment.Tenant, out tenant))
216+
{
217+
testTenant.Id = tenant;
218+
}
219+
}
220+
AzureRMCmdlet.DefaultProfile.Context = new AzureContext(testSubscription, testAccount, environment, testTenant);
202221
}
203222
}
204223

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/PermissiveRecordMatcherWithApiExclusion.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,24 @@ public string GetMatchingKey(System.Net.Http.HttpRequestMessage request)
5353

5454
public string GetMatchingKey(RecordEntry recordEntry)
5555
{
56-
var encodedPath = recordEntry.EncodedRequestUri;
57-
if (recordEntry.RequestUri.Contains("?&"))
56+
string path = recordEntry.RequestUri;
57+
if(!string.IsNullOrEmpty(recordEntry.EncodedRequestUri))
5858
{
59-
var updatedPath = recordEntry.RequestUri.Replace("?&", "?");
60-
61-
62-
string version;
63-
if (ContainsIgnoredProvider(updatedPath, out version))
64-
{
65-
updatedPath = RemoveOrReplaceApiVersion(updatedPath, version);
66-
}
59+
path = Encoding.UTF8.GetString(Convert.FromBase64String(recordEntry.EncodedRequestUri));
60+
}
6761

68-
encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(updatedPath));
62+
if (path.Contains("?&"))
63+
{
64+
path = path.Replace("?&", "?");
6965
}
7066

67+
string version;
68+
if (ContainsIgnoredProvider(path, out version))
69+
{
70+
path = RemoveOrReplaceApiVersion(path, version);
71+
}
72+
73+
var encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(path));
7174
return string.Format("{0} {1}", recordEntry.RequestMethod, encodedPath);
7275
}
7376

src/ResourceManager/Compute/Commands.Compute.Test/Common/ComputeTestController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void RunPsTestWorkflow(
9797
string mockName)
9898
{
9999
Dictionary<string, string> d = new Dictionary<string, string>();
100-
d.Add("Microsoft.Authorization", "2014-07-01-preview");
100+
d.Add("Microsoft.Authorization", null);
101101
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);
102102

103103
using (UndoContext context = UndoContext.Current)

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/DscExtensionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
55
{
66
public class DscExtensionTests
77
{
8-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
8+
[Fact]
99
[Trait(Category.AcceptanceType, Category.CheckIn)]
1010
public void TestGetAzureRmVMDscExtension()
1111
{

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
1919
{
2020
public class VirtualMachineProfileTests
2121
{
22-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
22+
[Fact]
2323
[Trait(Category.AcceptanceType, Category.CheckIn)]
2424
public void TestVirtualMachineProfile()
2525
{
2626
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineProfile");
2727
}
2828

29-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
29+
[Fact]
3030
[Trait(Category.AcceptanceType, Category.CheckIn)]
3131
public void TestVirtualMachineProfileWithoutAUC()
3232
{

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function Test-VirtualMachineProfile
116116
$imgRef = Get-DefaultCRPWindowsImageOffline -loc $loc;
117117
$p = ($imgRef | Set-AzureRmVMSourceImage -VM $p);
118118

119-
$subid = (Get-AzureRmSubscription -Current).SubscriptionId;
119+
$subid = (Get-AzureRmContext).Subscription.SubscriptionId;
120120

121121
$referenceUri = "/subscriptions/" + $subid + "/resourceGroups/RgTest1/providers/Microsoft.KeyVault/vaults/TestVault123";
122122
$certStore = "My";
@@ -283,7 +283,7 @@ function Test-VirtualMachineProfileWithoutAUC
283283
$imgRef = Get-DefaultCRPWindowsImageOffline -loc $loc;
284284
$p = ($imgRef | Set-AzureRmVMSourceImage -VM $p);
285285

286-
$subid = (Get-AzureRmSubscription -Current).SubscriptionId;
286+
$subid = (Get-AzureRmContext).Subscription.SubscriptionId;
287287

288288
$referenceUri = "/subscriptions/" + $subid + "/resourceGroups/RgTest1/providers/Microsoft.KeyVault/vaults/TestVault123";
289289
$certStore = "My";

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
1919
{
2020
public partial class VirtualMachineTests
2121
{
22-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
22+
[Fact]
2323
[Trait(Category.AcceptanceType, Category.CheckIn)]
2424
public void TestVirtualMachine()
2525
{

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function Test-VirtualMachine
179179
Assert-NotNull $aset;
180180
Assert-AreEqual $asetName $aset.Name;
181181

182-
$asetId = ('/subscriptions/' + (Get-AzureRmSubscription -Current).SubscriptionId + '/resourceGroups/' + $rgname + '/providers/Microsoft.Compute/availabilitySets/' + $asetName);
182+
$asetId = ('/subscriptions/' + (Get-AzureRmContext).Subscription.SubscriptionId + '/resourceGroups/' + $rgname + '/providers/Microsoft.Compute/availabilitySets/' + $asetName);
183183
$vmname2 = $vmname + '2';
184184
$p2 = New-AzureRmVMConfig -VMName $vmname2 -VMSize $vmsize -AvailabilitySetId $asetId;
185185
$p2.HardwareProfile = $p.HardwareProfile;

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/Common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Gets a valid storage account resource id
3636
#>
3737
function Get-StorageResourceId($rgname, $resourcename)
3838
{
39-
$subscription = (Get-AzureRmSubscription -Default).SubscriptionId
39+
$subscription = (Get-AzureRmContext).Subscription.SubscriptionId
4040
return "/subscriptions/$subscription/resourcegroups/$rgname/providers/microsoft.storage/storageaccounts/$resourcename"
4141
}
4242

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/OperationalInsightsScenarioTestBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
using Microsoft.Azure.Management.Resources;
2020
using Microsoft.Azure.Subscriptions;
2121
using Microsoft.Azure.Test;
22+
using Microsoft.Azure.Test.HttpRecorder;
2223
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2324
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
25+
using System.Collections.Generic;
2426

2527
namespace Microsoft.Azure.Commands.OperationalInsights.Test
2628
{
@@ -51,6 +53,10 @@ protected void SetupManagementClients()
5153

5254
protected void RunPowerShellTest(params string[] scripts)
5355
{
56+
Dictionary<string, string> d = new Dictionary<string, string>();
57+
d.Add("Microsoft.Authorization", null);
58+
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);
59+
5460
using (UndoContext context = UndoContext.Current)
5561
{
5662
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/StorageInsightTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ namespace Microsoft.Azure.Commands.OperationalInsights.Test
1919
{
2020
public class StorageInsightTests : OperationalInsightsScenarioTestBase
2121
{
22-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
22+
[Fact]
2323
[Trait(Category.AcceptanceType, Category.CheckIn)]
2424
public void TestStorageInsightCreateUpdateDelete()
2525
{
2626
RunPowerShellTest("Test-StorageInsightCreateUpdateDelete");
2727
}
2828

29-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
29+
[Fact]
3030
[Trait(Category.AcceptanceType, Category.CheckIn)]
3131
public void TestStorageInsightCreateFailsWithoutWorkspace()
3232
{

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleAssignmentTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ public void RaAuthorizationChangeLog()
3737
ResourcesController.NewInstance.RunPsTest("Test-RaAuthorizationChangeLog");
3838
}
3939

40-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
40+
[Fact(Skip = "Need to re-record test")]
4141
[Trait(Category.AcceptanceType, Category.CheckIn)]
4242
public void RaClassicAdmins()
4343
{
4444
ResourcesController.NewInstance.RunPsTest("Test-RaClassicAdmins");
4545
}
4646

47-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
47+
[Fact(Skip = "Need to re-record test")]
4848
[Trait(Category.AcceptanceType, Category.CheckIn)]
4949
public void RaNegativeScenarios()
5050
{
5151
ResourcesController.NewInstance.RunPsTest("Test-RaNegativeScenarios");
5252
}
5353

54-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
54+
[Fact(Skip = "Need to re-record test")]
5555
[Trait(Category.AcceptanceType, Category.CheckIn)]
5656
public void RaByScope()
5757
{

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/SqlTestsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected void RunPowerShellTest(params string[] scripts)
5757
{
5858
//HttpMockServer.Matcher = new PermissiveRecordMatcher();
5959
Dictionary<string, string> d = new Dictionary<string, string>();
60-
d.Add("Microsoft.Authorization", "2014-07-01-preview");
60+
d.Add("Microsoft.Authorization", null);
6161
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);
6262
// Enable undo functionality as well as mock recording
6363
using (UndoContext context = UndoContext.Current)

src/ServiceManagement/Services/Commands.Test/Profile/NewAzureProfileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void TestMakeRdfeCallWithCreatedProfile()
5656
ProfileTestController.NewRdfeInstance.RunPSTestWithToken((context, token) => string.Format("Test-NewAzureProfileInRDFEMode {0} {1} {2}", token, context.Account.Id, context.Subscription.Id));
5757
}
5858

59-
[Fact(Skip = "Hovsep: Move to ARM")]
59+
[Fact(Skip = "PSGet Migration: TODO Move to ARM")]
6060
[Trait(Category.AcceptanceType, Category.CheckIn)]
6161
public void TestMakeArmCallWithCreatedProfile()
6262
{

0 commit comments

Comments
 (0)