winget-cli

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

Pinning.cs (11991B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="Pinning.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 AppInstallerCLIE2ETests.Helpers;
     11     using NUnit.Framework;
     12     using static AppInstallerCLIE2ETests.Helpers.TestCommon;
     13 
     14     /// <summary>
     15     /// Test upgrading pinned packages.
     16     /// </summary>
     17     public class Pinning : BaseCommand
     18     {
     19         /// <summary>
     20         /// Set up for all tests.
     21         /// </summary>
     22         [SetUp]
     23         public void Setup()
     24         {
     25             // All tests use TestExeInstaller; try to clean it up for failure cases,
     26             // then install the base version for pinning
     27             TestCommon.RunAICLICommand("uninstall", "AppInstallerTest.TestExeInstaller");
     28             TestCommon.RunAICLICommand("install", "AppInstallerTest.TestExeInstaller -v 1.0.0.0");
     29             TestCommon.RunAICLICommand("pin remove", "AppInstallerTest.TestExeInstaller");
     30         }
     31 
     32         /// <summary>
     33         /// Clean up done after all the tests here.
     34         /// </summary>
     35         [OneTimeTearDown]
     36         public void OneTimeTearDown()
     37         {
     38             TestCommon.RunAICLICommand("pin remove", "AppInstallerTest.TestExeInstaller");
     39             TestCommon.RunAICLICommand("uninstall", "AppInstallerTest.TestExeInstaller");
     40         }
     41 
     42         // All tests do roughly the same with different types of pins:
     43         // * Check that the available version shown by list is the latest
     44         // * Check that the available version shown by upgrade is appropriate for the pin,
     45         //   including checks with flags to include pinned.
     46         // * Check that an upgrade installs the right version
     47 
     48         /// <summary>
     49         /// Tests upgrading a package when there are no pins on it.
     50         /// </summary>
     51         [Test]
     52         public void UpgradeWithNoPins()
     53         {
     54             RunCommandResult result;
     55 
     56             result = TestCommon.RunAICLICommand("list", "AppInstallerTest.TestExeInstaller");
     57             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     58             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "List shows the latest available version");
     59 
     60             result = TestCommon.RunAICLICommand("upgrade", string.Empty);
     61             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     62             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "The latest upgrade-able version is the same if there are no pins");
     63         }
     64 
     65         /// <summary>
     66         /// Tests upgrading a package when it has a pinning pin.
     67         /// </summary>
     68         [Test]
     69         public void UpgradeWithPinningPin()
     70         {
     71             RunCommandResult result;
     72             string installDir = Path.GetTempPath();
     73 
     74             // The base version of this app does not log /Version, but it still includes the version number in the log file name.
     75             Assert.True(TestCommon.VerifyTestExeInstalled(installDir, "1.0.0.0"), "Base version installed");
     76 
     77             result = TestCommon.RunAICLICommand("pin add", "AppInstallerTest.TestExeInstaller");
     78             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     79 
     80             result = TestCommon.RunAICLICommand("list", "AppInstallerTest.TestExeInstaller");
     81             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     82             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "List shows the latest available version");
     83 
     84             result = TestCommon.RunAICLICommand("upgrade", string.Empty);
     85             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     86             Assert.IsFalse(result.StdOut.Contains("2.0.0.0"), "Pin hides latest available version");
     87             Assert.IsTrue(result.StdOut.Contains("package(s) have pins that prevent upgrade"));
     88 
     89             result = TestCommon.RunAICLICommand("upgrade", "--all");
     90             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode, "Upgrade succeeds with nothing to upgrade");
     91 
     92             Assert.True(TestCommon.VerifyTestExeInstalled(installDir, "1.0.0.0"), "No newer version installed");
     93 
     94             result = TestCommon.RunAICLICommand("upgrade", "--include-pinned");
     95             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
     96             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "Argument makes available version show up");
     97 
     98             result = TestCommon.RunAICLICommand("upgrade", "--all --include-pinned");
     99             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode, "Upgrade succeeds");
    100             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir, "/Version 2.0.0.0"));
    101         }
    102 
    103         /// <summary>
    104         /// Tests upgrading a package when it has a gating pin that allows updating to another version.
    105         /// </summary>
    106         [Test]
    107         public void UpgradeWithGatingPin()
    108         {
    109             RunCommandResult result;
    110             string installDir = Path.GetTempPath();
    111 
    112             var pinResult = TestCommon.RunAICLICommand("pin add", "AppInstallerTest.TestExeInstaller --version 1.0.*");
    113             Assert.AreEqual(Constants.ErrorCode.S_OK, pinResult.ExitCode);
    114 
    115             result = TestCommon.RunAICLICommand("list", "AppInstallerTest.TestExeInstaller");
    116             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    117             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "List shows the latest available version");
    118 
    119             result = TestCommon.RunAICLICommand("upgrade", string.Empty);
    120             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    121             Assert.IsFalse(result.StdOut.Contains("2.0.0.0"), "Pin hides latest available version");
    122             Assert.IsTrue(result.StdOut.Contains("1.0.1.0"), "Version matching pin gated version shows up");
    123 
    124             result = TestCommon.RunAICLICommand("upgrade", "--all");
    125             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode, "Upgrade succeeds");
    126             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir, "/Version 1.0.1.0"));
    127         }
    128 
    129         /// <summary>
    130         /// Tests upgrading a package when it has a gating pin that blocks all other versions.
    131         /// </summary>
    132         [Test]
    133         public void UpgradeWithGatingPinToCurrent()
    134         {
    135             RunCommandResult result;
    136 
    137             result = TestCommon.RunAICLICommand("pin add", "AppInstallerTest.TestExeInstaller --version 1.0.0.*");
    138             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    139 
    140             result = TestCommon.RunAICLICommand("list", "AppInstallerTest.TestExeInstaller");
    141             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    142             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "List shows the latest available version");
    143 
    144             result = TestCommon.RunAICLICommand("upgrade", string.Empty);
    145             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    146             Assert.IsFalse(result.StdOut.Contains("2.0.0.0"), "Pin hides latest available version");
    147             Assert.IsTrue(result.StdOut.Contains("package(s) have pins that prevent upgrade"));
    148 
    149             result = TestCommon.RunAICLICommand("upgrade", "AppInstallerTest.TestExeInstaller");
    150             Assert.AreEqual(Constants.ErrorCode.ERROR_PACKAGE_IS_PINNED, result.ExitCode, "No upgrades available due to pin");
    151         }
    152 
    153         /// <summary>
    154         /// Tests upgrading a package when it has a blocking pin.
    155         /// </summary>
    156         [Test]
    157         public void UpgradeWithBlockingPin()
    158         {
    159             RunCommandResult result;
    160 
    161             var pinResult = TestCommon.RunAICLICommand("pin add", "AppInstallerTest.TestExeInstaller --blocking");
    162             Assert.AreEqual(Constants.ErrorCode.S_OK, pinResult.ExitCode);
    163 
    164             result = TestCommon.RunAICLICommand("list", "AppInstallerTest.TestExeInstaller");
    165             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    166             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "List shows the latest available version");
    167 
    168             result = TestCommon.RunAICLICommand("upgrade", string.Empty);
    169             Assert.IsFalse(result.StdOut.Contains("2.0.0.0"), "Pin hides latest available version");
    170             Assert.IsTrue(result.StdOut.Contains("package(s) have pins that prevent upgrade"));
    171 
    172             result = TestCommon.RunAICLICommand("upgrade", "AppInstallerTest.TestExeInstaller");
    173             Assert.AreEqual(Constants.ErrorCode.ERROR_PACKAGE_IS_PINNED, result.ExitCode, "No upgrades available due to pin");
    174         }
    175 
    176         /// <summary>
    177         /// Tests upgrading a package when it has a pinning pin and the --force flag is used.
    178         /// </summary>
    179         [Test]
    180         public void ForceUpgradeWithPinningPin()
    181         {
    182             RunCommandResult result;
    183             string installDir = Path.GetTempPath();
    184 
    185             result = TestCommon.RunAICLICommand("pin add", "AppInstallerTest.TestExeInstaller");
    186             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    187 
    188             result = TestCommon.RunAICLICommand("upgrade", "--force");
    189             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    190             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "--force argument shows latest version");
    191 
    192             result = TestCommon.RunAICLICommand("upgrade", "--all --force");
    193             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    194             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir, "/Version 2.0.0.0"), "--force argument installs last version despite pin");
    195         }
    196 
    197         /// <summary>
    198         /// Tests upgrading a package when it has a gating pin and the --force flag is used.
    199         /// </summary>
    200         [Test]
    201         public void ForceUpgradeWithGatingPin()
    202         {
    203             RunCommandResult result;
    204             string installDir = Path.GetTempPath();
    205 
    206             var pinResult = TestCommon.RunAICLICommand("pin add", "AppInstallerTest.TestExeInstaller --version 1.0.*");
    207             Assert.AreEqual(Constants.ErrorCode.S_OK, pinResult.ExitCode);
    208 
    209             result = TestCommon.RunAICLICommand("upgrade", "--force");
    210             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    211             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "--force argument shows latest version");
    212 
    213             result = TestCommon.RunAICLICommand("upgrade", "--all --force");
    214             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode, "Upgrade succeeds");
    215             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir, "/Version 2.0.0.0"));
    216         }
    217 
    218         /// <summary>
    219         /// Tests upgrading a package when it has a blocking pin and the --force flag is used.
    220         /// </summary>
    221         [Test]
    222         public void ForceUpgradeWithBlockingPin()
    223         {
    224             RunCommandResult result;
    225             string installDir = Path.GetTempPath();
    226 
    227             var pinResult = TestCommon.RunAICLICommand("pin add", "AppInstallerTest.TestExeInstaller --blocking");
    228             Assert.AreEqual(Constants.ErrorCode.S_OK, pinResult.ExitCode);
    229 
    230             result = TestCommon.RunAICLICommand("upgrade", "--force");
    231             Assert.IsTrue(result.StdOut.Contains("2.0.0.0"), "--force argument shows latest version");
    232 
    233             result = TestCommon.RunAICLICommand("upgrade", "--all --force");
    234             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode, "Upgrade succeeds");
    235             Assert.True(TestCommon.VerifyTestExeInstalledAndCleanup(installDir, "/Version 2.0.0.0"));
    236         }
    237     }
    238 }