forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpgradeCommand.cs
More file actions
204 lines (173 loc) · 10.2 KB
/
Copy pathUpgradeCommand.cs
File metadata and controls
204 lines (173 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// -----------------------------------------------------------------------------
// <copyright file="UpgradeCommand.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
// -----------------------------------------------------------------------------
namespace AppInstallerCLIE2ETests
{
using System.IO;
using AppInstallerCLIE2ETests.Helpers;
using NUnit.Framework;
/// <summary>
/// Test upgrade command.
/// </summary>
public class UpgradeCommand : BaseCommand
{
private static readonly string DenyUpgradePackage = "AppInstallerTest.TestUpgradeDeny";
/// <summary>
/// Tear down.
/// </summary>
[TearDown]
public void TearDown()
{
// Due to its properties, this being present is problematic.
TestCommon.RunAICLICommand("uninstall", DenyUpgradePackage);
}
/// <summary>
/// Test upgrade portable package.
/// </summary>
[Test]
public void UpgradePortable()
{
string installDir = TestCommon.GetPortablePackagesDirectory();
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestPortableExe";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = fileName = "AppInstallerTestExeInstaller.exe";
var result = TestCommon.RunAICLICommand("install", "AppInstallerTest.TestPortableExe -v 1.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully installed"));
var result2 = TestCommon.RunAICLICommand("upgrade", $"{packageId} -v 2.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, result2.ExitCode);
Assert.True(result2.StdOut.Contains("Successfully installed"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, true);
}
/// <summary>
/// Test upgrade portable package with arp mismatch.
/// </summary>
[Test]
public void UpgradePortableARPMismatch()
{
string packageId = "AppInstallerTest.TestPortableExe";
string productCode = packageId + "_" + Constants.TestSourceIdentifier;
var installResult = TestCommon.RunAICLICommand("install", "AppInstallerTest.TestPortableExe -v 1.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, installResult.ExitCode);
Assert.True(installResult.StdOut.Contains("Successfully installed"));
// Modify packageId to cause mismatch.
TestCommon.ModifyPortableARPEntryValue(productCode, Constants.WinGetPackageIdentifier, "testPackageId");
var upgradeResult = TestCommon.RunAICLICommand("upgrade", $"{packageId} -v 2.0.0.0");
// Reset and perform uninstall cleanup
TestCommon.ModifyPortableARPEntryValue(productCode, Constants.WinGetPackageIdentifier, packageId);
TestCommon.RunAICLICommand("uninstall", $"--product-code {productCode}");
Assert.AreNotEqual(Constants.ErrorCode.S_OK, upgradeResult.ExitCode);
Assert.True(upgradeResult.StdOut.Contains("Portable package from a different source already exists"));
}
/// <summary>
/// Test upgrade portable package force override.
/// </summary>
[Test]
public void UpgradePortableForcedOverride()
{
string installDir = TestCommon.GetPortablePackagesDirectory();
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestPortableExe";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = fileName = "AppInstallerTestExeInstaller.exe";
var installResult = TestCommon.RunAICLICommand("install", "AppInstallerTest.TestPortableExe -v 1.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, installResult.ExitCode);
Assert.True(installResult.StdOut.Contains("Successfully installed"));
// Modify packageId and sourceId to cause mismatch.
TestCommon.ModifyPortableARPEntryValue(productCode, Constants.WinGetPackageIdentifier, "testPackageId");
TestCommon.ModifyPortableARPEntryValue(productCode, Constants.WinGetSourceIdentifier, "testSourceId");
var upgradeResult = TestCommon.RunAICLICommand("upgrade", $"{packageId} -v 2.0.0.0 --force");
Assert.AreEqual(Constants.ErrorCode.S_OK, upgradeResult.ExitCode);
Assert.True(upgradeResult.StdOut.Contains("Successfully installed"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, true);
}
/// <summary>
/// Test upgrade portable package uninstall previous version.
/// </summary>
[Test]
public void UpgradePortableUninstallPrevious()
{
string installDir = TestCommon.GetPortablePackagesDirectory();
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestPortableExe";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = fileName = "AppInstallerTestExeInstaller.exe";
var result = TestCommon.RunAICLICommand("install", $"{packageId} -v 1.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully installed"));
var result2 = TestCommon.RunAICLICommand("upgrade", $"{packageId} -v 3.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, result2.ExitCode);
Assert.True(result2.StdOut.Contains("Successfully installed"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, true);
}
/// <summary>
/// Test upgrade with deny behavior.
/// </summary>
[Test]
public void UpgradeBehaviorDeny()
{
string packageId = DenyUpgradePackage;
var result = TestCommon.RunAICLICommand("install", $"{packageId} -v 1.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully installed"));
var result2 = TestCommon.RunAICLICommand("upgrade", $"{packageId} -v 2.0.0.0");
Assert.AreEqual(Constants.ErrorCode.APPINSTALLER_CLI_ERROR_INSTALL_UPGRADE_NOT_SUPPORTED, result2.ExitCode);
Assert.True(result2.StdOut.Contains("package cannot be upgraded using winget"));
}
/// <summary>
/// Test upgrade portable package machine scope.
/// </summary>
[Test]
public void UpgradePortableMachineScope()
{
string installDir = TestCommon.GetRandomTestDir();
WinGetSettingsHelper.ConfigureInstallBehavior(Constants.PortablePackageMachineRoot, installDir);
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestPortableExe";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = fileName = "AppInstallerTestExeInstaller.exe";
var result = TestCommon.RunAICLICommand("install", $"{packageId} -v 1.0.0.0 --scope machine");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully installed"));
var result2 = TestCommon.RunAICLICommand("upgrade", $"{packageId} -v 2.0.0.0");
WinGetSettingsHelper.ConfigureInstallBehavior(Constants.PortablePackageMachineRoot, string.Empty);
Assert.AreEqual(Constants.ErrorCode.S_OK, result2.ExitCode);
Assert.True(result2.StdOut.Contains("Successfully installed"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, true, TestCommon.Scope.Machine);
}
/// <summary>
/// Test upgrade zip portable package.
/// </summary>
[Test]
public void UpgradeZip_Portable()
{
string installDir = TestCommon.GetPortablePackagesDirectory();
string packageId, commandAlias, fileName, packageDirName, productCode;
packageId = "AppInstallerTest.TestZipInstallerWithPortable";
packageDirName = productCode = packageId + "_" + Constants.TestSourceIdentifier;
commandAlias = "TestPortable.exe";
fileName = "AppInstallerTestExeInstaller.exe";
var result = TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestZipInstallerWithPortable -v 1.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("Successfully installed"));
var result2 = TestCommon.RunAICLICommand("upgrade", $"{packageId} -v 2.0.0.0");
Assert.AreEqual(Constants.ErrorCode.S_OK, result2.ExitCode);
Assert.True(result2.StdOut.Contains("Successfully installed"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, true, TestCommon.Scope.User);
}
/// <summary>
/// Test upgrade when a new dependency is added that is not installed.
/// </summary>
[Test]
public void UpgradeAddsDependency()
{
var result = TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestUpgradeAddsDependency -v 1.0 --verbose");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
result = TestCommon.RunAICLICommand("upgrade", $"AppInstallerTest.TestUpgradeAddsDependency");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
}
}
}