Ejemplo n.º 1
0
        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 = GetManagedDependenciesPath(functionAppRoot);

                var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

                // Create DependencyManager and process the requirements.psd1 file at the function app root.
                var dependencyManager = new TestDependencyManager();
                dependencyManager.Initialize(functionLoadRequest);

                // Configure the dependencyManager to not throw in the RunSaveModuleCommand call after 2 tries.
                dependencyManager.ShouldNotThrowAfterCount = 2;

                // Try to install the function app dependencies.
                dependencyManager.InstallFunctionAppDependencies(null, _testLogger);

                // 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
                bool correctLogCount = (_testLogger.FullLog.Count == 4);
                Assert.True(correctLogCount);

                // The first log should say "Installing FunctionApp dependent modules."
                Assert.Contains(PowerShellWorkerStrings.InstallingFunctionAppDependentModules, _testLogger.FullLog[0]);

                // The subsequent two logs should contain the following: "Fail to install module"
                for (int index = 1; index < _testLogger.FullLog.Count - 1; index++)
                {
                    Assert.Contains("Fail to install module", _testLogger.FullLog[index]);
                    var currentAttempt = dependencyManager.GetCurrentAttemptMessage(index);
                    Assert.Contains(currentAttempt, _testLogger.FullLog[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(dependencyManager.DownloadedModuleInfo, _testLogger.FullLog[3]);

                // Lastly, DependencyError should be null since the module was downloaded successfully after two tries.
                Assert.Null(dependencyManager.DependencyError);
            }
            finally
            {
                TestCaseCleanup();
            }
        }
Ejemplo n.º 2
0
        public void TestManagedDependencyRetryLogicMaxNumberOfTries()
        {
            try
            {
                // Test case setup
                var requirementsDirectoryName     = "BasicRequirements";
                var functionFolderPath            = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName, "FunctionDirectory");
                var functionAppRoot               = Path.Combine(_dependencyManagementDirectory, requirementsDirectoryName);
                var managedDependenciesFolderPath = GetManagedDependenciesPath(functionAppRoot);

                var functionLoadRequest = GetFuncLoadRequest(functionFolderPath, true);

                // Create DependencyManager and process the requirements.psd1 file at the function app root.
                var dependencyManager = new TestDependencyManager();
                dependencyManager.Initialize(functionLoadRequest);

                // Try to install the function app dependencies.
                dependencyManager.InstallFunctionAppDependencies(null, _testLogger);

                // Here we will get four logs: one that says that we are installing the
                // dependencies, and three for failing to install the module.
                bool correctLogCount = (_testLogger.FullLog.Count == 4);
                Assert.True(correctLogCount);

                // The first log should say "Installing FunctionApp dependent modules."
                Assert.Contains(PowerShellWorkerStrings.InstallingFunctionAppDependentModules, _testLogger.FullLog[0]);

                // The subsequent logs should contain the following:
                for (int index = 1; index < _testLogger.FullLog.Count; index++)
                {
                    Assert.Contains("Fail to install module", _testLogger.FullLog[index]);
                    var currentAttempt = dependencyManager.GetCurrentAttemptMessage(index);
                    Assert.Contains(currentAttempt, _testLogger.FullLog[index]);
                }

                // Lastly, DependencyError should get set after unsuccessfully  retyring 3 times.
                Assert.NotNull(dependencyManager.DependencyError);
                Assert.Contains("Fail to install FunctionApp dependencies. Error:", dependencyManager.DependencyError.Message);
            }
            finally
            {
                TestCaseCleanup();
            }
        }
Ejemplo n.º 3
0
        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 = GetManagedDependenciesPath(functionAppRoot);
                var functionLoadRequest           = GetFuncLoadRequest(functionFolderPath, true);

                // Create DependencyManager and process the requirements.psd1 file at the function app root.
                var dependencyManager = new TestDependencyManager();
                dependencyManager.Initialize(functionLoadRequest);

                // Configure the dependency manager to mimic a successful download.
                dependencyManager.SuccessfulDownload = true;

                // Install the function app dependencies.
                dependencyManager.InstallFunctionAppDependencies(null, _testLogger);

                // Here we will get two logs: one that says that we are installing the dependencies, and one for a successful download.
                bool correctLogCount = (_testLogger.FullLog.Count == 2);
                Assert.True(correctLogCount);

                // The first log should say "Installing FunctionApp dependent modules."
                Assert.Contains(PowerShellWorkerStrings.InstallingFunctionAppDependentModules, _testLogger.FullLog[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(dependencyManager.DownloadedModuleInfo, _testLogger.FullLog[1]);

                // Lastly, DependencyError should be null since the module was downloaded successfully.
                Assert.Null(dependencyManager.DependencyError);
            }
            finally
            {
                TestCaseCleanup();
            }
        }