Skip to content

Commit e28b0be

Browse files
author
Hovsep Mkrtchyan
committed
Fixing module path for compute PIR.psd1 and AzurePreview.psd1 modules
1 parent 306c142 commit e28b0be

File tree

4 files changed

+74
-37
lines changed

4 files changed

+74
-37
lines changed

src/Common/Commands.Common/CmdletExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static class CmdletExtensions
2525
{
2626
public static string AsAbsoluteLocation(this string realtivePath)
2727
{
28-
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, realtivePath);
28+
return Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, realtivePath));
2929
}
3030

3131
public static string TryResolvePath(this PSCmdlet psCmdlet, string path)

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

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -272,57 +272,81 @@ public void SetupModules(params string[] modules)
272272
this.modules.AddRange(modules);
273273
}
274274

275+
275276
public virtual Collection<PSObject> RunPowerShellTest(params string[] scripts)
276277
{
277278
using (var powershell = System.Management.Automation.PowerShell.Create(RunspaceMode.NewRunspace))
278279
{
279-
SetupPowerShellModules(powershell);
280+
return ExecuteShellTest(powershell, null, scripts);
281+
}
282+
}
283+
public virtual Collection<PSObject> RunPowerShellTest(IEnumerable<string> setupScripts, IEnumerable<string> scripts)
284+
{
285+
using (var powershell = System.Management.Automation.PowerShell.Create(RunspaceMode.NewRunspace))
286+
{
287+
return ExecuteShellTest(powershell, setupScripts, scripts);
288+
}
289+
}
280290

281-
Collection<PSObject> output = null;
282-
for (int i = 0; i < scripts.Length; ++i)
283-
{
284-
Console.WriteLine(scripts[i]);
285-
powershell.AddScript(scripts[i]);
286-
}
287-
try
288-
{
289-
powershell.Runspace.Events.Subscribers.Clear();
290-
powershell.Streams.Error.Clear();
291-
output = powershell.Invoke();
291+
private Collection<PSObject> ExecuteShellTest(
292+
System.Management.Automation.PowerShell powershell,
293+
IEnumerable<string> setupScripts,
294+
IEnumerable<string> scripts)
295+
{
296+
SetupPowerShellModules(powershell, null);
292297

293-
if (powershell.Streams.Error.Count > 0)
294-
{
295-
var sb = new StringBuilder();
298+
Collection<PSObject> output = null;
296299

297-
sb.AppendLine("Test failed due to a non-empty error stream, check the error stream in the test log for more details.");
298-
sb.AppendLine(string.Format("{0} total Errors", powershell.Streams.Error.Count));
299-
foreach (var error in powershell.Streams.Error)
300-
{
301-
sb.AppendLine(error.Exception.ToString());
302-
}
300+
foreach (var script in scripts)
301+
{
302+
Console.WriteLine(script);
303+
powershell.AddScript(script);
304+
}
305+
try
306+
{
307+
powershell.Runspace.Events.Subscribers.Clear();
308+
powershell.Streams.Error.Clear();
309+
output = powershell.Invoke();
303310

304-
throw new RuntimeException(sb.ToString());
311+
if (powershell.Streams.Error.Count > 0)
312+
{
313+
var sb = new StringBuilder();
314+
315+
sb.AppendLine("Test failed due to a non-empty error stream, check the error stream in the test log for more details.");
316+
sb.AppendLine(string.Format("{0} total Errors", powershell.Streams.Error.Count));
317+
foreach (var error in powershell.Streams.Error)
318+
{
319+
sb.AppendLine(error.Exception.ToString());
305320
}
306321

307-
return output;
308-
}
309-
catch (Exception psException)
310-
{
311-
powershell.LogPowerShellException(psException);
312-
throw;
313-
}
314-
finally
315-
{
316-
powershell.LogPowerShellResults(output);
317-
powershell.Streams.Error.Clear();
322+
throw new RuntimeException(sb.ToString());
318323
}
324+
325+
return output;
326+
}
327+
catch (Exception psException)
328+
{
329+
powershell.LogPowerShellException(psException);
330+
throw;
331+
}
332+
finally
333+
{
334+
powershell.LogPowerShellResults(output);
335+
powershell.Streams.Error.Clear();
319336
}
320337
}
321338

322-
private void SetupPowerShellModules(System.Management.Automation.PowerShell powershell)
339+
private void SetupPowerShellModules(System.Management.Automation.PowerShell powershell, IEnumerable<string> setupScripts)
323340
{
324341
powershell.AddScript("$error.clear()");
325342
powershell.AddScript(string.Format("cd \"{0}\"", AppDomain.CurrentDomain.BaseDirectory));
343+
if (setupScripts != null)
344+
{
345+
foreach(var script in setupScripts)
346+
{
347+
powershell.AddScript(script);
348+
}
349+
}
326350

327351
foreach (string moduleName in modules)
328352
{

src/ServiceManagement/Common/Commands.ScenarioTest/DiagnosticsExtension/DiagnosticsExtensionTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.WindowsAzure.Management.Compute;
2020
using Microsoft.WindowsAzure.Management.Network;
2121
using Microsoft.WindowsAzure.Management.Storage;
22+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2223
using System.Collections.Generic;
2324
using Xunit;
2425

@@ -63,7 +64,13 @@ protected void RunPowerShellTest(params string[] scripts)
6364
helper.SetupEnvironment(AzureModule.AzureServiceManagement);
6465
helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());
6566

66-
helper.RunPowerShellTest(scripts);
67+
var scriptEnvPath = new List<string>();
68+
scriptEnvPath.Add(
69+
string.Format(
70+
"$env:PSModulePath=\"{0};$env:PSModulePath\"",
71+
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute".AsAbsoluteLocation()));
72+
73+
helper.RunPowerShellTest(scriptEnvPath, scripts);
6774
}
6875
}
6976

src/ServiceManagement/Common/Commands.ScenarioTest/ServiceManagement/ServiceManagementTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ protected void RunPowerShellTest(params string[] scripts)
6262
helper.SetupEnvironment(AzureModule.AzureServiceManagement);
6363
helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());
6464

65-
helper.RunPowerShellTest(scripts);
65+
var scriptEnvPath = new List<string>();
66+
scriptEnvPath.Add(
67+
string.Format(
68+
"$env:PSModulePath=\"{0};$env:PSModulePath\"",
69+
Path.Combine(EnvironmentSetupHelper.PackageDirectory, @"ServiceManagement\Azure\Compute").AsAbsoluteLocation()));
70+
71+
helper.RunPowerShellTest(scriptEnvPath.ToArray(), scripts);
6672
}
6773
}
6874
}

0 commit comments

Comments
 (0)