Skip to content

Commit d72c686

Browse files
committed
Add E2E tests for source edit
1 parent 2a6da61 commit d72c686

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/AppInstallerCLIE2ETests/SourceCommand.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,83 @@ public void SourceForceReset()
258258
Assert.False(result.StdOut.Contains(Constants.TestSourceName));
259259
Assert.False(result.StdOut.Contains(Constants.TestSourceUrl));
260260
}
261+
262+
/// <summary>
263+
/// Test source add with explicit flag, edit the source to not be explicit.
264+
/// </summary>
265+
[Test]
266+
public void SourceEdit()
267+
{
268+
// Remove the test source.
269+
TestCommon.RunAICLICommand("source remove", Constants.TestSourceName);
270+
271+
// Add source as explicit and verify it is explicit.
272+
var addResult = TestCommon.RunAICLICommand("source add", $"SourceTest {Constants.TestSourceUrl} --trust-level trusted --explicit");
273+
Assert.AreEqual(Constants.ErrorCode.S_OK, addResult.ExitCode);
274+
Assert.True(addResult.StdOut.Contains("Done"));
275+
276+
var searchResult = TestCommon.RunAICLICommand("search", "TestExampleInstaller");
277+
Assert.AreEqual(Constants.ErrorCode.ERROR_NO_SOURCES_DEFINED, searchResult.ExitCode);
278+
Assert.True(searchResult.StdOut.Contains("No sources defined; add one with 'source add' or reset to defaults with 'source reset'"));
279+
280+
// Run the edit, this should be S_OK with "Done" as it changed the state to not-explicit.
281+
var editResult = TestCommon.RunAICLICommand("source edit", $"SourceTest");
282+
Assert.AreEqual(Constants.ErrorCode.S_OK, editResult.ExitCode);
283+
Assert.True(editResult.StdOut.Contains("Done"));
284+
285+
// Run it again, this should result in S_OK with no changes and a message that the source is already in that state.
286+
var editResult2 = TestCommon.RunAICLICommand("source edit", $"SourceTest");
287+
Assert.AreEqual(Constants.ErrorCode.S_OK, editResult2.ExitCode);
288+
Assert.True(editResult2.StdOut.Contains("The source named 'SourceTest' is already in that desired state."));
289+
290+
// Now verify it is no longer explicit by running the search again without adding the source parameter.
291+
var searchResult2 = TestCommon.RunAICLICommand("search", "TestExampleInstaller");
292+
Assert.AreEqual(Constants.ErrorCode.S_OK, searchResult2.ExitCode);
293+
Assert.True(searchResult2.StdOut.Contains("TestExampleInstaller"));
294+
Assert.True(searchResult2.StdOut.Contains("AppInstallerTest.TestExampleInstaller"));
295+
TestCommon.RunAICLICommand("source remove", $"-n SourceTest");
296+
}
297+
298+
/// <summary>
299+
/// Test override of a default source via edit command.
300+
/// </summary>
301+
[Test]
302+
public void SourceEditOverrideDefault()
303+
{
304+
// Force Reset Sources
305+
var resetResult = TestCommon.RunAICLICommand("source reset", "--force");
306+
Assert.AreEqual(Constants.ErrorCode.S_OK, resetResult.ExitCode);
307+
308+
// Verify it is explicit true. Explicit is the only boolean value in the output.
309+
var listResult = TestCommon.RunAICLICommand("source list", "winget-font");
310+
Assert.AreEqual(Constants.ErrorCode.S_OK, listResult.ExitCode);
311+
Assert.True(listResult.StdOut.Contains("true"));
312+
313+
var editResult = TestCommon.RunAICLICommand("source edit", "winget-font");
314+
Assert.AreEqual(Constants.ErrorCode.S_OK, editResult.ExitCode);
315+
Assert.True(editResult.StdOut.Contains("Done"));
316+
317+
// Verify that after edit it is now explicit false.
318+
var listResult2 = TestCommon.RunAICLICommand("source list", "winget-font");
319+
Assert.AreEqual(Constants.ErrorCode.S_OK, listResult2.ExitCode);
320+
Assert.True(listResult2.StdOut.Contains("false"));
321+
322+
// Remove the source. This should correctly tombstone it, even though it is overridden.
323+
var removeResult = TestCommon.RunAICLICommand("source remove", "winget-font");
324+
Assert.AreEqual(Constants.ErrorCode.S_OK, removeResult.ExitCode);
325+
Assert.True(removeResult.StdOut.Contains("Done"));
326+
327+
var listResult3 = TestCommon.RunAICLICommand("source list", "winget-font");
328+
Assert.AreEqual(Constants.ErrorCode.ERROR_SOURCE_NAME_DOES_NOT_EXIST, listResult3.ExitCode);
329+
330+
// Force Reset Sources
331+
var resetResult2 = TestCommon.RunAICLICommand("source reset", "--force");
332+
Assert.AreEqual(Constants.ErrorCode.S_OK, resetResult2.ExitCode);
333+
334+
// Verify it is back to being explicit true.
335+
var listResult4 = TestCommon.RunAICLICommand("source list", "winget-font");
336+
Assert.AreEqual(Constants.ErrorCode.S_OK, listResult4.ExitCode);
337+
Assert.True(listResult4.StdOut.Contains("true"));
338+
}
261339
}
262340
}

0 commit comments

Comments
 (0)