forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigureCommand.cs
More file actions
218 lines (187 loc) · 9.87 KB
/
Copy pathConfigureCommand.cs
File metadata and controls
218 lines (187 loc) · 9.87 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// -----------------------------------------------------------------------------
// <copyright file="ConfigureCommand.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>
/// `Configure` command tests.
/// </summary>
public class ConfigureCommand
{
private const string CommandAndAgreementsAndVerbose = "configure --accept-configuration-agreements --verbose";
/// <summary>
/// Setup done once before all the tests here.
/// </summary>
[OneTimeSetUp]
public void OneTimeSetup()
{
this.DeleteTxtFiles();
}
/// <summary>
/// Teardown done once after all the tests here.
/// </summary>
[OneTimeTearDown]
public void OneTimeTeardown()
{
this.DeleteTxtFiles();
}
/// <summary>
/// Simple test to confirm that a resource without a module specified can be discovered in the PSGallery.
/// Intentionally has no settings to force a failure, but only after acquiring the module.
/// </summary>
[Test]
public void ConfigureFromGallery()
{
TestCommon.EnsureModuleState(Constants.GalleryTestModuleName, present: false);
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\PSGallery_NoModule_NoSettings.yml"), timeOut: 120000);
Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_SET_APPLY_FAILED, result.ExitCode);
Assert.True(result.StdOut.Contains("The configuration unit failed while attempting to test the current system state."));
}
/// <summary>
/// Simple test to confirm that a resource with a module specified can be discovered in a local repository that doesn't support resource discovery.
/// </summary>
[Test]
public void ConfigureFromTestRepo()
{
TestCommon.EnsureModuleState(Constants.SimpleTestModuleName, present: false);
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.yml"));
Assert.AreEqual(0, result.ExitCode);
// The configuration creates a file next to itself with the given contents
string targetFilePath = TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.txt");
FileAssert.Exists(targetFilePath);
Assert.AreEqual("Contents!", File.ReadAllText(targetFilePath));
Assert.True(Directory.Exists(
Path.Combine(
TestCommon.GetExpectedModulePath(TestCommon.TestModuleLocation.Default),
Constants.SimpleTestModuleName)));
}
/// <summary>
/// Simple test to confirm that the module was installed in the right location.
/// </summary>
/// <param name="location">Location to pass.</param>
[TestCase(TestCommon.TestModuleLocation.CurrentUser)]
[TestCase(TestCommon.TestModuleLocation.AllUsers)]
[TestCase(TestCommon.TestModuleLocation.WinGetModulePath)]
[TestCase(TestCommon.TestModuleLocation.Custom)]
[TestCase(TestCommon.TestModuleLocation.Default)]
public void ConfigureFromTestRepo_Location(TestCommon.TestModuleLocation location)
{
TestCommon.EnsureModuleState(Constants.SimpleTestModuleName, present: false);
string args = TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo_Location.yml");
if (location == TestCommon.TestModuleLocation.CurrentUser)
{
args += " --module-path currentuser";
}
else if (location == TestCommon.TestModuleLocation.AllUsers)
{
args += " --module-path allusers";
}
else if (location == TestCommon.TestModuleLocation.Default)
{
args += " --module-path default";
}
else if (location == TestCommon.TestModuleLocation.Custom)
{
args += " --module-path " + TestCommon.GetExpectedModulePath(location);
}
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, args);
Assert.AreEqual(0, result.ExitCode);
Assert.True(Directory.Exists(Path.Combine(
TestCommon.GetExpectedModulePath(location),
Constants.SimpleTestModuleName)));
}
/// <summary>
/// One resource fails, but the other is not dependent and should be executed.
/// </summary>
[Test]
public void IndependentResourceWithSingleFailure()
{
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\IndependentResources_OneFailure.yml"));
Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_SET_APPLY_FAILED, result.ExitCode);
// The configuration creates a file next to itself with the given contents
string targetFilePath = TestCommon.GetTestDataFile("Configuration\\IndependentResources_OneFailure.txt");
FileAssert.Exists(targetFilePath);
Assert.AreEqual("Contents!", File.ReadAllText(targetFilePath));
}
/// <summary>
/// One resource fails, and the dependent resource should not be executed.
/// </summary>
[Test]
public void DependentResourceWithFailure()
{
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\DependentResources_Failure.yml"));
Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_SET_APPLY_FAILED, result.ExitCode);
// The configuration creates a file next to itself with the given contents
string targetFilePath = TestCommon.GetTestDataFile("Configuration\\DependentResources_Failure.txt");
FileAssert.DoesNotExist(targetFilePath);
}
/// <summary>
/// The configuration server unexpectedly exits. Winget should continue to operate properly.
/// </summary>
[Test]
public void ConfigServerUnexpectedExit()
{
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\ConfigServerUnexpectedExit.yml"));
Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_SET_APPLY_FAILED, result.ExitCode);
// The configuration creates a file next to itself with the given contents
string targetFilePath = TestCommon.GetTestDataFile("Configuration\\ConfigServerUnexpectedExit.txt");
FileAssert.DoesNotExist(targetFilePath);
}
/// <summary>
/// Resource name case-insensitive test.
/// </summary>
[Test]
public void ResourceCaseInsensitive()
{
TestCommon.EnsureModuleState(Constants.SimpleTestModuleName, present: false);
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\ResourceCaseInsensitive.yml"));
Assert.AreEqual(0, result.ExitCode);
// The configuration creates a file next to itself with the given contents
string targetFilePath = TestCommon.GetTestDataFile("Configuration\\ResourceCaseInsensitive.txt");
FileAssert.Exists(targetFilePath);
Assert.AreEqual("Contents!", File.ReadAllText(targetFilePath));
}
/// <summary>
/// Simple test to configure from an https configuration file.
/// </summary>
[Test]
public void ConfigureFromHttpsConfigurationFile()
{
string args = $"{Constants.TestSourceUrl}/TestData/Configuration/Configure_TestRepo_Location.yml";
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, args);
Assert.AreEqual(0, result.ExitCode);
}
/// <summary>
/// Runs a configuration, then changes the state and runs it again from history.
/// </summary>
[Test]
public void ConfigureFromHistory()
{
var result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.yml"));
Assert.AreEqual(0, result.ExitCode);
// The configuration creates a file next to itself with the given contents
string targetFilePath = TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.txt");
FileAssert.Exists(targetFilePath);
Assert.AreEqual("Contents!", File.ReadAllText(targetFilePath));
File.WriteAllText(targetFilePath, "Changed contents!");
string guid = TestCommon.GetConfigurationInstanceIdentifierFor("Configure_TestRepo.yml");
result = TestCommon.RunAICLICommand(CommandAndAgreementsAndVerbose, $"-h {guid}");
Assert.AreEqual(0, result.ExitCode);
FileAssert.Exists(targetFilePath);
Assert.AreEqual("Contents!", File.ReadAllText(targetFilePath));
}
private void DeleteTxtFiles()
{
// Delete all .txt files in the test directory; they are placed there by the tests
foreach (string file in Directory.GetFiles(TestCommon.GetTestDataFile("Configuration"), "*.txt"))
{
File.Delete(file);
}
}
}
}