winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

ResumeCommand.cs (5828B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="ResumeCommand.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace AppInstallerCLIE2ETests
      8 {
      9     using System.IO;
     10     using System.Linq;
     11     using AppInstallerCLIE2ETests.Helpers;
     12     using NUnit.Framework;
     13 
     14     /// <summary>
     15     /// Test download command.
     16     /// </summary>
     17     public class ResumeCommand : BaseCommand
     18     {
     19         /// <summary>
     20         /// One time setup.
     21         /// </summary>
     22         [OneTimeSetUp]
     23         public void OneTimeSetup()
     24         {
     25             WinGetSettingsHelper.ConfigureFeature("resume", true);
     26         }
     27 
     28         /// <summary>
     29         /// One time teardown.
     30         /// </summary>
     31         [OneTimeTearDown]
     32         public void OneTimeTearDown()
     33         {
     34             WinGetSettingsHelper.ConfigureFeature("resume", false);
     35         }
     36 
     37         /// <summary>
     38         /// Installs a test exe installer and verifies that the checkpoint index is cleaned up.
     39         /// </summary>
     40         [Test]
     41         public void InstallExe_VerifyIndexDoesNotExist()
     42         {
     43             var checkpointsDir = TestCommon.GetCheckpointsDirectory();
     44 
     45             // If the checkpoints directory does not yet exist, set to 0. The directory should be created when the command is invoked.
     46             int initialCheckpointsCount = Directory.Exists(checkpointsDir) ? Directory.GetFiles(checkpointsDir).Length : 0;
     47 
     48             var installDir = TestCommon.GetRandomTestDir();
     49             var result = TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestExeInstaller --silent -l {installDir}");
     50             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     51             Assert.True(result.StdOut.Contains("Successfully installed"));
     52             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir, "/execustom"));
     53 
     54             int actualCheckpointsCount = Directory.GetFiles(checkpointsDir).Length;
     55 
     56             // The checkpoints count should not change as the index file should be cleaned up after a successful install.
     57             Assert.AreEqual(initialCheckpointsCount, actualCheckpointsCount);
     58         }
     59 
     60         /// <summary>
     61         /// Verifies that an error message is shown when a resume id does not exist.
     62         /// </summary>
     63         [Test]
     64         public void ResumeIdNotFound()
     65         {
     66             var resumeResult = TestCommon.RunAICLICommand("resume", "-g invalidResumeId");
     67             Assert.AreEqual(Constants.ErrorCode.ERROR_RESUME_ID_NOT_FOUND, resumeResult.ExitCode);
     68         }
     69 
     70         /// <summary>
     71         /// Test install a package that returns REBOOT_REQUIRED_TO_FINISH and verify that the checkpoint database is properly cleaned up.
     72         /// </summary>
     73         [Test]
     74         public void InstallRequiresRebootToFinish()
     75         {
     76             var checkpointsDir = TestCommon.GetCheckpointsDirectory();
     77             int initialCheckpointsCount = Directory.Exists(checkpointsDir) ? Directory.GetDirectories(checkpointsDir).Length : 0;
     78 
     79             var installDir = TestCommon.GetRandomTestDir();
     80             var result = TestCommon.RunAICLICommand("install", $"TestRebootRequired --custom \"/ExitCode 9\" -l {installDir}");
     81 
     82             // REBOOT_REQUIRED_TO_FINISH is treated as a success.
     83             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     84             Assert.True(result.StdOut.Contains("Restart your PC to finish installation."));
     85             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir));
     86 
     87             int actualCheckpointsCount = Directory.GetDirectories(checkpointsDir).Length;
     88 
     89             // Checkpoint database should be cleaned up since resume is not needed to complete installation.
     90             Assert.AreEqual(initialCheckpointsCount, actualCheckpointsCount);
     91         }
     92 
     93         /// <summary>
     94         /// Test install a package that returns REBOOT_REQUIRED_FOR_INSTALL and verify that resume command can be called successfully.
     95         /// </summary>
     96         [Test]
     97         public void InstallRequiresRebootForInstall()
     98         {
     99             var checkpointsDir = TestCommon.GetCheckpointsDirectory();
    100 
    101             int initialCheckpointsCount = Directory.Exists(checkpointsDir) ? Directory.GetDirectories(checkpointsDir).Length : 0;
    102 
    103             var installDir = TestCommon.GetRandomTestDir();
    104             var result = TestCommon.RunAICLICommand("install", $"TestRebootRequired --custom \"/ExitCode 10\" -l {installDir}");
    105             Assert.AreEqual(Constants.ErrorCode.ERROR_INSTALL_REBOOT_REQUIRED_FOR_INSTALL, result.ExitCode);
    106             Assert.True(result.StdOut.Contains("Your PC will restart to finish installation."));
    107             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir));
    108 
    109             int actualCheckpointsCount = Directory.GetDirectories(checkpointsDir).Length;
    110             Assert.AreEqual(initialCheckpointsCount + 1, actualCheckpointsCount);
    111 
    112             var checkpointsDirectoryInfo = new DirectoryInfo(checkpointsDir);
    113 
    114             var checkpoint = checkpointsDirectoryInfo.GetDirectories()
    115              .OrderByDescending(f => f.LastWriteTime)
    116              .First();
    117 
    118             // Resume output should be the same as the install result.
    119             var resumeResult = TestCommon.RunAICLICommand("resume", $"-g {checkpoint.Name}");
    120             Assert.AreEqual(Constants.ErrorCode.ERROR_INSTALL_REBOOT_REQUIRED_FOR_INSTALL, resumeResult.ExitCode);
    121             Assert.True(resumeResult.StdOut.Contains("Your PC will restart to finish installation."));
    122             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir));
    123         }
    124     }
    125 }