Skip to content

Commit 87aabf2

Browse files
Update tests
1 parent c7d1e8b commit 87aabf2

File tree

2 files changed

+15
-38
lines changed

2 files changed

+15
-38
lines changed

test/Unit/DependencyManagement/DependencyManagementTests.cs

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

7876
try
7977
{
80-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory))
78+
using (var dependencyManager = new DependencyManager(_dependencyManagementDirectory))
8179
{
8280
dependencyManager.Initialize(_testLogger);
8381
}
@@ -95,14 +93,11 @@ public void TestManagedDependencyBasicRequirements()
9593
{
9694
// Test case setup.
9795
var requirementsDirectoryName = "BasicRequirements";
98-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
9996
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
10097
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
10198

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

@@ -126,13 +121,11 @@ public void TestManagedDependencyEmptyHashtableRequirement()
126121
{
127122
// Test case setup.
128123
var requirementsDirectoryName = "EmptyHashtableRequirement";
129-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
130124
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
131125
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
132-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
133126

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

@@ -150,10 +143,9 @@ public void TestManagedDependencyNoHashtableRequirementShouldThrow()
150143
{
151144
// Test case setup.
152145
var requirementsDirectoryName = "NoHashtableRequirements";
153-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
154-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
146+
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
155147

156-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, logger: _testLogger))
148+
using (var dependencyManager = new DependencyManager(functionAppRoot, logger: _testLogger))
157149
{
158150
// Trying to set the functionApp dependencies should throw since requirements.psd1 is not a hash table.
159151
var exception = Assert.Throws<DependencyInstallationException>(
@@ -169,10 +161,9 @@ public void TestManagedDependencyInvalidRequirementsFormatShouldThrow()
169161
{
170162
// Test case setup.
171163
var requirementsDirectoryName = "InvalidRequirementsFormat";
172-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
173-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
164+
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
174165

175-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, logger: _testLogger))
166+
using (var dependencyManager = new DependencyManager(functionAppRoot, logger: _testLogger))
176167
{
177168
// Trying to set the functionApp dependencies should throw since the module version
178169
// in requirements.psd1 is not in a valid format.
@@ -190,10 +181,9 @@ public void TestManagedDependencyNoRequirementsFileShouldThrow()
190181
{
191182
// Test case setup.
192183
var requirementsDirectoryName = "ModuleThatDoesNotExist";
193-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
194-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
184+
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
195185

196-
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, logger: _testLogger))
186+
using (var dependencyManager = new DependencyManager(functionAppRoot, logger: _testLogger))
197187
{
198188
// Trying to set the functionApp dependencies should throw since no
199189
// requirements.psd1 is found at the function app root.
@@ -212,16 +202,14 @@ public void TestManagedDependencySuccessfulModuleDownload()
212202
{
213203
// Test case setup.
214204
var requirementsDirectoryName = "BasicRequirements";
215-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
216205
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
217206
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
218-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
219207

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

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

@@ -258,17 +246,14 @@ public void TestManagedDependencySuccessfulModuleDownloadAfterTwoTries()
258246
{
259247
// Test case setup
260248
var requirementsDirectoryName = "BasicRequirements";
261-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
262249
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
263250
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
264251

265-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
266-
267252
// Configure MockModuleProvider to not throw in the RunSaveModuleCommand call after 2 tries.
268253
var mockModuleProvider = new MockModuleProvider { ShouldNotThrowAfterCount = 2 };
269254

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

@@ -318,14 +303,11 @@ public void TestManagedDependencyRetryLogicMaxNumberOfTries()
318303
{
319304
// Test case setup
320305
var requirementsDirectoryName = "BasicRequirements";
321-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
322306
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
323307
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
324308

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

@@ -372,16 +354,13 @@ public void FunctionAppExecutionShouldStopIfNoPreviousDependenciesAreInstalled()
372354
{
373355
// Test case setup
374356
var requirementsDirectoryName = "BasicRequirements";
375-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
376357
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
377358
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
378359

379-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
380-
381360
// Create DependencyManager and configure it to mimic being unable to reach
382361
// the PSGallery to retrieve the latest module version
383362
using (var dependencyManager = new DependencyManager(
384-
functionLoadRequest.Metadata.Directory,
363+
functionAppRoot,
385364
new MockModuleProvider { GetLatestModuleVersionThrows = true },
386365
logger: _testLogger))
387366
{
@@ -409,15 +388,13 @@ public void FunctionAppExecutionShouldContinueIfPreviousDependenciesExist()
409388
{
410389
// Test case setup
411390
var requirementsDirectoryName = "BasicRequirements";
412-
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
413391
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
414392
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
415-
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
416393

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

test/Unit/DependencyManagement/DependencyManagerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private void VerifyMessageLogged(LogLevel expectedLogLevel, string expectedMessa
372372
private DependencyManager CreateDependencyManagerWithMocks()
373373
{
374374
return new DependencyManager(
375-
requestMetadataDirectory: null,
375+
functionAppRootPath: null,
376376
moduleProvider: null,
377377
storage: _mockStorage.Object,
378378
installedDependenciesLocator: _mockInstalledDependenciesLocator.Object,

0 commit comments

Comments
 (0)