forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfigureExportCommand.cs
More file actions
204 lines (180 loc) · 11.1 KB
/
ConfigureExportCommand.cs
File metadata and controls
204 lines (180 loc) · 11.1 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="ConfigureExportCommand.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;
using NUnit.Framework.Internal;
/// <summary>
/// `Configure export` command tests.
/// </summary>
public class ConfigureExportCommand
{
private const string Command = "configure export";
private const string ShowCommand = "configure show";
private string previousPathValue = string.Empty;
/// <summary>
/// Set up.
/// </summary>
[OneTimeSetUp]
public void BaseSetup()
{
TestCommon.SetupTestSource(false);
var installDir = TestCommon.GetRandomTestDir();
TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestPackageExport -v 1.0.0.0 --silent -l {installDir}");
this.previousPathValue = System.Environment.GetEnvironmentVariable("PATH");
System.Environment.SetEnvironmentVariable("PATH", this.previousPathValue + ";" + installDir);
DSCv3ResourceTestBase.EnsureTestResourcePresence();
}
/// <summary>
/// Tear down.
/// </summary>
[OneTimeTearDown]
public void BaseTeardown()
{
TestCommon.RunAICLICommand("uninstall", "AppInstallerTest.TestPackageExport");
TestCommon.TearDownTestSource();
if (!string.IsNullOrEmpty(this.previousPathValue))
{
System.Environment.SetEnvironmentVariable("PATH", this.previousPathValue);
}
}
/// <summary>
/// Export a specific package.
/// </summary>
[Test]
public void ExportTestPackage()
{
var exportDir = TestCommon.GetRandomTestDir();
var exportFile = Path.Combine(exportDir, "exported.yml");
var result = TestCommon.RunAICLICommand(Command, $"--package-id AppInstallerTest.TestPackageExport -o {exportFile}");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(File.Exists(exportFile));
// Check exported file is readable and validate content
var showResult = TestCommon.RunAICLICommand(ShowCommand, $"-f {exportFile}");
Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode);
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source"));
Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));
Assert.True(showResult.StdOut.Contains($"type: {Constants.TestSourceType}"));
Assert.True(showResult.StdOut.Contains($"argument: {Constants.TestSourceUrl}"));
Assert.True(showResult.StdOut.Contains($"name: {Constants.TestSourceName}"));
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Package"));
Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_AppInstallerTest.TestPackageExport]"));
Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_{Constants.TestSourceType}"));
Assert.True(showResult.StdOut.Contains("id: AppInstallerTest.TestPackageExport"));
Assert.True(showResult.StdOut.Contains($"source: {Constants.TestSourceName}"));
}
/// <summary>
/// Export a specific package with related configuration.
/// </summary>
[Test]
public void ExportTestPackageWithPackageSettings()
{
var exportDir = TestCommon.GetRandomTestDir();
var exportFile = Path.Combine(exportDir, "exported.yml");
var result = TestCommon.RunAICLICommand(Command, $"--package-id AppInstallerTest.TestPackageExport --module AppInstallerTest --resource TestResource -o {exportFile}");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(File.Exists(exportFile));
// Check exported file is readable and validate content
var showResult = TestCommon.RunAICLICommand(ShowCommand, $"-f {exportFile}");
Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode);
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source"));
Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));
Assert.True(showResult.StdOut.Contains($"type: {Constants.TestSourceType}"));
Assert.True(showResult.StdOut.Contains($"argument: {Constants.TestSourceUrl}"));
Assert.True(showResult.StdOut.Contains($"name: {Constants.TestSourceName}"));
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Package"));
Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_AppInstallerTest.TestPackageExport]"));
Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_{Constants.TestSourceType}"));
Assert.True(showResult.StdOut.Contains("id: AppInstallerTest.TestPackageExport"));
Assert.True(showResult.StdOut.Contains($"source: {Constants.TestSourceName}"));
Assert.True(showResult.StdOut.Contains("AppInstallerTest/TestResource"));
Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_AppInstallerTest.TestPackageExport"));
Assert.True(showResult.StdOut.Contains("data: TestData"));
}
/// <summary>
/// Export a specific package with version.
/// </summary>
[Test]
public void ExportTestPackageWithVersion()
{
var exportDir = TestCommon.GetRandomTestDir();
var exportFile = Path.Combine(exportDir, "exported.yml");
var result = TestCommon.RunAICLICommand(Command, $"--package-id AppInstallerTest.TestPackageExport --include-versions -o {exportFile}");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(File.Exists(exportFile));
// Check exported file is readable and validate content
var showResult = TestCommon.RunAICLICommand(ShowCommand, $"-f {exportFile}");
Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode);
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source"));
Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));
Assert.True(showResult.StdOut.Contains($"type: {Constants.TestSourceType}"));
Assert.True(showResult.StdOut.Contains($"argument: {Constants.TestSourceUrl}"));
Assert.True(showResult.StdOut.Contains($"name: {Constants.TestSourceName}"));
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Package"));
Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_AppInstallerTest.TestPackageExport]"));
Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_{Constants.TestSourceType}"));
Assert.True(showResult.StdOut.Contains("id: AppInstallerTest.TestPackageExport"));
Assert.True(showResult.StdOut.Contains($"source: {Constants.TestSourceName}"));
Assert.True(showResult.StdOut.Contains("version: 1.0.0.0"));
}
/// <summary>
/// Export all.
/// </summary>
[Test]
public void ExportAll()
{
var exportDir = TestCommon.GetRandomTestDir();
var exportFile = Path.Combine(exportDir, "exported.yml");
var result = TestCommon.RunAICLICommand(Command, $"--all -o {exportFile}", timeOut: 1200000);
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(File.Exists(exportFile));
// Check exported file is readable and validate content
var showResult = TestCommon.RunAICLICommand(ShowCommand, $"-f {exportFile}", timeOut: 1200000);
Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode);
Assert.True(showResult.StdOut.Contains("Microsoft.PowerShell"));
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/UserSettingsFile"));
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/AdminSettings"));
Assert.True(showResult.StdOut.Contains("Microsoft.Windows.Settings/WindowsSettings"));
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source"));
Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));
Assert.True(showResult.StdOut.Contains($"type: {Constants.TestSourceType}"));
Assert.True(showResult.StdOut.Contains($"argument: {Constants.TestSourceUrl}"));
Assert.True(showResult.StdOut.Contains($"name: {Constants.TestSourceName}"));
Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Package"));
Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_AppInstallerTest.TestPackageExport]"));
Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_{Constants.TestSourceType}"));
Assert.True(showResult.StdOut.Contains("id: AppInstallerTest.TestPackageExport"));
Assert.True(showResult.StdOut.Contains($"source: {Constants.TestSourceName}"));
Assert.True(showResult.StdOut.Contains("AppInstallerTest/TestResource"));
Assert.True(showResult.StdOut.Contains($"Dependencies: {Constants.TestSourceName}_AppInstallerTest.TestPackageExport"));
Assert.True(showResult.StdOut.Contains("data: TestData"));
}
/// <summary>
/// Export a specific package that's not installed.
/// </summary>
[Test]
public void ExportFailedWithNotFoundPackage()
{
var exportDir = TestCommon.GetRandomTestDir();
var exportFile = Path.Combine(exportDir, "exported.yml");
var result = TestCommon.RunAICLICommand(Command, $"--package-id NotFound.NotFound -o {exportFile}");
Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode);
}
/// <summary>
/// Export all with specific package id.
/// </summary>
[Test]
public void ExportFailedWithAllAndSpecificPackage()
{
var exportDir = TestCommon.GetRandomTestDir();
var exportFile = Path.Combine(exportDir, "exported.yml");
var result = TestCommon.RunAICLICommand(Command, $"--all --package-id AppInstallerTest.TestPackageExport -o {exportFile}");
Assert.AreEqual(Constants.ErrorCode.ERROR_INVALID_CL_ARGUMENTS, result.ExitCode);
}
}
}