public void TestManagedDependencySuccessfulModuleDownloadAfterTwoTries() { try { // 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)) { dependencyManager.Initialize(_testLogger); // Try to install the function app dependencies. var dependencyError = dependencyManager.InstallFunctionAppDependencies(PowerShell.Create(), PowerShell.Create, _testLogger); var relevantLogs = _testLogger.FullLog.Where( message => message.StartsWith("Error: Failed to install module") || message.StartsWith("Trace: Installing function app required modules") || message.StartsWith("Trace: Module name")).ToList(); // Here we will get four logs: // - one that say that we are installing the dependencies // - two that say that we failed to download the module // - one for a successful module download Assert.Equal(4, relevantLogs.Count); Assert.Contains("Installing function app required modules", relevantLogs[0]); // The subsequent two logs should contain the following: "Fail to install module" for (int index = 1; index < relevantLogs.Count - 1; index++) { Assert.Contains("Failed to install module", relevantLogs[index]); var currentAttempt = DependencySnapshotInstaller.GetCurrentAttemptMessage(index); Assert.Contains(currentAttempt, relevantLogs[index]); } // Successful module download log after two retries. // In the overwritten RunSaveModuleCommand method, we saved in DownloadedModuleInfo the module name and version. // This same information is logged after running save-module, so validate that they match. Assert.Contains(mockModuleProvider.DownloadedModuleInfo, relevantLogs[3]); // Lastly, DependencyError should be null since the module was downloaded successfully after two tries. Assert.Null(dependencyError); } } finally { TestCaseCleanup(); } }
public void TestManagedDependencySuccessfulModuleDownload() { try { // 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)) { dependencyManager.Initialize(_testLogger); // Install the function app dependencies. var dependencyError = dependencyManager.InstallFunctionAppDependencies(PowerShell.Create(), PowerShell.Create, _testLogger); var relevantLogs = _testLogger.FullLog.Where( message => message.StartsWith("Trace: Module name") || message.StartsWith("Trace: Installing FunctionApp dependent modules")).ToList(); // Here we will get two logs: one that says that we are installing the dependencies, and one for a successful download. Assert.Equal(2, relevantLogs.Count); // The first log should say "Installing FunctionApp dependent modules." Assert.Contains(PowerShellWorkerStrings.InstallingFunctionAppDependentModules, relevantLogs[0]); // In the overwritten RunSaveModuleCommand method, we saved in DownloadedModuleInfo the module name and version. // This same information is logged after running save-module, so validate that they match. Assert.Contains(mockModuleProvider.DownloadedModuleInfo, relevantLogs[1]); // Lastly, DependencyError should be null since the module was downloaded successfully. Assert.Null(dependencyError); } } finally { TestCaseCleanup(); } }