Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco-Gamino committed Oct 6, 2022
1 parent 887c882 commit 5e38ae4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
51 changes: 14 additions & 37 deletions test/Unit/DependencyManagement/DependencyManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ private string InitializeManagedDependenciesDirectory(string functionAppRootPath
private void TestCaseCleanup()
{
// We run a test case clean up to reset DependencyManager.Dependencies and DependencyManager.DependenciesPath
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, "DirectoryThatDoesNotExist");
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

try
{
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory))
using (var dependencyManager = new DependencyManager(_dependencyManagementDirectory))
{
dependencyManager.Initialize(_testLogger);
}
Expand All @@ -97,14 +95,11 @@ public void TestManagedDependencyBasicRequirements()
{
// Test case setup.
var requirementsDirectoryName = "BasicRequirements";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);

var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

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

Expand All @@ -128,13 +123,11 @@ public void TestManagedDependencyEmptyHashtableRequirement()
{
// Test case setup.
var requirementsDirectoryName = "EmptyHashtableRequirement";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

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

Expand All @@ -152,10 +145,9 @@ public void TestManagedDependencyNoHashtableRequirementShouldThrow()
{
// Test case setup.
var requirementsDirectoryName = "NoHashtableRequirements";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);

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

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

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

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

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

Expand Down Expand Up @@ -260,17 +248,14 @@ public void TestManagedDependencySuccessfulModuleDownloadAfterTwoTries()
{
// Test case setup
var requirementsDirectoryName = "BasicRequirements";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);

var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

// Configure MockModuleProvider to not throw in the RunSaveModuleCommand call after 2 tries.
var mockModuleProvider = new MockModuleProvider { ShouldNotThrowAfterCount = 2 };

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

Expand Down Expand Up @@ -320,14 +305,11 @@ public void TestManagedDependencyRetryLogicMaxNumberOfTries()
{
// Test case setup
var requirementsDirectoryName = "BasicRequirements";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);

var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

// Create DependencyManager and process the requirements.psd1 file at the function app root.
using (var dependencyManager = new DependencyManager(functionLoadRequest.Metadata.Directory, new MockModuleProvider(), logger: _testLogger))
using (var dependencyManager = new DependencyManager(functionAppRoot, new MockModuleProvider(), logger: _testLogger))
{
dependencyManager.Initialize(_testLogger);

Expand Down Expand Up @@ -374,16 +356,13 @@ public void FunctionAppExecutionShouldStopIfNoPreviousDependenciesAreInstalled()
{
// Test case setup
var requirementsDirectoryName = "BasicRequirements";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);

var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

// Create DependencyManager and configure it to mimic being unable to reach
// the PSGallery to retrieve the latest module version
using (var dependencyManager = new DependencyManager(
functionLoadRequest.Metadata.Directory,
functionAppRoot,
new MockModuleProvider { GetLatestModuleVersionThrows = true },
logger: _testLogger))
{
Expand Down Expand Up @@ -411,15 +390,13 @@ public void FunctionAppExecutionShouldContinueIfPreviousDependenciesExist()
{
// Test case setup
var requirementsDirectoryName = "BasicRequirements";
var functionFolderPath = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
var functionAppRoot = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
var managedDependenciesFolderPath = InitializeManagedDependenciesDirectory(functionAppRoot);
var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

// Create DependencyManager and configure it to mimic being unable to reach
// the PSGallery to retrive the latest module version
using (var dependencyManager = new DependencyManager(
functionLoadRequest.Metadata.Directory,
functionAppRoot,
new MockModuleProvider { GetLatestModuleVersionThrows = true },
logger: _testLogger))
{
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/DependencyManagement/DependencyManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void VerifyMessageLogged(LogLevel expectedLogLevel, string expectedMessa
private DependencyManager CreateDependencyManagerWithMocks()
{
return new DependencyManager(
requestMetadataDirectory: null,
functionAppRootPath: null,
moduleProvider: null,
storage: _mockStorage.Object,
installedDependenciesLocator: _mockInstalledDependenciesLocator.Object,
Expand Down

0 comments on commit 5e38ae4

Please sign in to comment.