Skip to content

Commit bbf56b3

Browse files
author
Anthony Staples
committed
Fix test cases, remove extra cmdlet import
1 parent f4cfa72 commit bbf56b3

File tree

3 files changed

+15
-41
lines changed

3 files changed

+15
-41
lines changed

src/RequestProcessor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,6 @@ private StreamingMessage ProcessFunctionMetadataRequest(StreamingMessage request
376376

377377
response.FunctionMetadataResponse.FunctionMetadataResults.AddRange(WorkerIndexingHelper.IndexFunctions(request.FunctionsMetadataRequest.FunctionAppDirectory));
378378

379-
string rawresp = JsonSerializer.Serialize<FunctionMetadataResponse>(response.FunctionMetadataResponse);
380-
381379
return response;
382380
}
383381

src/WorkerIndexing/WorkerIndexingHelper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ internal static IEnumerable<RpcFunctionMetadata> IndexFunctions(string baseDir)
1919
List<RpcFunctionMetadata> indexedFunctions = new List<RpcFunctionMetadata>();
2020

2121
InitialSessionState initial = InitialSessionState.CreateDefault();
22-
initial.ImportPSModule(new string[] { "AzureFunctionsHelpers" });
2322
Runspace runspace = RunspaceFactory.CreateRunspace(initial);
2423
runspace.Open();
2524
System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create();
2625
ps.Runspace = runspace;
27-
//ps.AddCommand("Import-Module").AddArgument("C:\\Program Files\\WindowsPowerShell\\Modules\\AzureFunctionsHelpers\\AzureFunctionsHelpers.dll").Invoke();
26+
2827
ps.AddCommand("Get-FunctionsMetadata").AddArgument(baseDir);
2928
string outputString = string.Empty;
3029
foreach (PSObject rawMetadata in ps.Invoke())

test/Unit/DependencyManagement/DependencyManagementTests.cs

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ private string InitializeManagedDependenciesDirectory(string functionAppRootPath
7474
private void TestCaseCleanup()
7575
{
7676
// We run a test case clean up to reset DependencyManager.Dependencies and DependencyManager.DependenciesPath
77-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, "DirectoryThatDoesNotExist");
78-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
7977

8078
try
8179
{
82-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory))
80+
using (var dependencyManager = new DependencyManager(_dependencyManagementDirectory))
8381
{
8482
dependencyManager.Initialize(_testLogger);
8583
}
@@ -97,14 +95,11 @@ public void TestManagedDependencyBasicRequirements()
9795
{
9896
// Test case setup.
9997
var requirementsDirectoryName = "BasicRequirements";
100-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
10198
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
10299
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
103100

104-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
105-
106101
// Create DependencyManager and process the requirements.psd1 file at the function app root.
107-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, logger: _testLogger))
102+
using (var dependencyManager = new DependencyManager(functionAppRoot, logger: _testLogger))
108103
{
109104
var currentDependenciesPath = dependencyManager.Initialize(_testLogger);
110105

@@ -128,13 +123,11 @@ public void TestManagedDependencyEmptyHashtableRequirement()
128123
{
129124
// Test case setup.
130125
var requirementsDirectoryName = "EmptyHashtableRequirement";
131-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
132126
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
133127
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
134-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
135128

136129
// Create DependencyManager and process the requirements.psd1 file at the function app root.
137-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, logger: _testLogger))
130+
using (var dependencyManager = new DependencyManager(functionAppRoot, logger: _testLogger))
138131
{
139132
var currentDependenciesPath = dependencyManager.Initialize(_testLogger);
140133

@@ -152,10 +145,9 @@ public void TestManagedDependencyNoHashtableRequirementShouldThrow()
152145
{
153146
// Test case setup.
154147
var requirementsDirectoryName = "NoHashtableRequirements";
155-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
156-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
148+
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
157149

158-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, logger: _testLogger))
150+
using (var dependencyManager = new DependencyManager(functionAppRoot, logger: _testLogger))
159151
{
160152
// Trying to set the functionApp dependencies should throw since requirements.psd1 is not a hash table.
161153
var exception = Assert.Throws<DependencyInstallationException>(
@@ -171,10 +163,9 @@ public void TestManagedDependencyInvalidRequirementsFormatShouldThrow()
171163
{
172164
// Test case setup.
173165
var requirementsDirectoryName = "InvalidRequirementsFormat";
174-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
175-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
166+
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
176167

177-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, logger: _testLogger))
168+
using (var dependencyManager = new DependencyManager(functionAppRoot, logger: _testLogger))
178169
{
179170
// Trying to set the functionApp dependencies should throw since the module version
180171
// in requirements.psd1 is not in a valid format.
@@ -192,10 +183,9 @@ public void TestManagedDependencyNoRequirementsFileShouldThrow()
192183
{
193184
// Test case setup.
194185
var requirementsDirectoryName = "ModuleThatDoesNotExist";
195-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
196-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
186+
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
197187

198-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, logger: _testLogger))
188+
using (var dependencyManager = new DependencyManager(functionAppRoot, logger: _testLogger))
199189
{
200190
// Trying to set the functionApp dependencies should throw since no
201191
// requirements.psd1 is found at the function app root.
@@ -214,16 +204,14 @@ public void TestManagedDependencySuccessfulModuleDownload()
214204
{
215205
// Test case setup.
216206
var requirementsDirectoryName = "BasicRequirements";
217-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
218207
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
219208
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
220-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
221209

222210
// Configure MockModuleProvider to mimic a successful download.
223211
var mockModuleProvider = new MockModuleProvider { SuccessfulDownload = true };
224212

225213
// Create DependencyManager and process the requirements.psd1 file at the function app root.
226-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, mockModuleProvider, logger: _testLogger))
214+
using (var dependencyManager = new DependencyManager(functionAppRoot, mockModuleProvider, logger: _testLogger))
227215
{
228216
dependencyManager.Initialize(_testLogger);
229217

@@ -260,17 +248,14 @@ public void TestManagedDependencySuccessfulModuleDownloadAfterTwoTries()
260248
{
261249
// Test case setup
262250
var requirementsDirectoryName = "BasicRequirements";
263-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
264251
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
265252
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
266253

267-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
268-
269254
// Configure MockModuleProvider to not throw in the RunSaveModuleCommand call after 2 tries.
270255
var mockModuleProvider = new MockModuleProvider { ShouldNotThrowAfterCount = 2 };
271256

272257
// Create DependencyManager and process the requirements.psd1 file at the function app root.
273-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, mockModuleProvider, logger: _testLogger))
258+
using (var dependencyManager = new DependencyManager(functionAppRoot, mockModuleProvider, logger: _testLogger))
274259
{
275260
dependencyManager.Initialize(_testLogger);
276261

@@ -320,14 +305,11 @@ public void TestManagedDependencyRetryLogicMaxNumberOfTries()
320305
{
321306
// Test case setup
322307
var requirementsDirectoryName = "BasicRequirements";
323-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
324308
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
325309
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
326310

327-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
328-
329311
// Create DependencyManager and process the requirements.psd1 file at the function app root.
330-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, new MockModuleProvider(), logger: _testLogger))
312+
using (var dependencyManager = new DependencyManager(functionAppRoot, new MockModuleProvider(), logger: _testLogger))
331313
{
332314
dependencyManager.Initialize(_testLogger);
333315

@@ -374,16 +356,13 @@ public void FunctionAppExecutionShouldStopIfNoPreviousDependenciesAreInstalled()
374356
{
375357
// Test case setup
376358
var requirementsDirectoryName = "BasicRequirements";
377-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
378359
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
379360
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
380361

381-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
382-
383362
// Create DependencyManager and configure it to mimic being unable to reach
384363
// the PSGallery to retrieve the latest module version
385364
using (var dependencyManager = new DependencyManager(
386-
functionLoadRequest.Metadata.Directory,
365+
functionAppRoot,
387366
new MockModuleProvider { GetLatestModuleVersionThrows = true },
388367
logger: _testLogger))
389368
{
@@ -411,15 +390,13 @@ public void FunctionAppExecutionShouldContinueIfPreviousDependenciesExist()
411390
{
412391
// Test case setup
413392
var requirementsDirectoryName = "BasicRequirements";
414-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
415393
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
416394
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
417-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
418395

419396
// Create DependencyManager and configure it to mimic being unable to reach
420397
// the PSGallery to retrive the latest module version
421398
using (var dependencyManager = new DependencyManager(
422-
functionLoadRequest.Metadata.Directory,
399+
functionAppRoot,
423400
new MockModuleProvider { GetLatestModuleVersionThrows = true },
424401
logger: _testLogger))
425402
{

0 commit comments

Comments
 (0)