forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to export all installed packages in winget configure expo…
…rt (microsoft#5156) The feature is in parity with `winget export` command. Except the exported file is in winget configuration yaml format. The exported file is ready to be used with winget configure commands. New additions: - When exporting a specific package (existing functionality), in addition we'll search the source to find the package before export. If the package is not from well known source, the source is exported as well. Supports exporting the version like `winget export` too. - Added `--all` to export all installed packages. We reuse the workfow in `winget export` to collect packages to export. For non well known sources, the sources are exported as well. `--all` cannot be used with other specific package export arguments. Manually validated and added e2e tests.
- Loading branch information
Showing
12 changed files
with
403 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
271 changes: 179 additions & 92 deletions
271
src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// ----------------------------------------------------------------------------- | ||
// <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"; | ||
|
||
/// <summary> | ||
/// Set up. | ||
/// </summary> | ||
[OneTimeSetUp] | ||
public void BaseSetup() | ||
{ | ||
TestCommon.SetupTestSource(false); | ||
WinGetSettingsHelper.ConfigureFeature("configureExport", true); | ||
var installDir = TestCommon.GetRandomTestDir(); | ||
TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestPackageExport -v 1.0.0.0 --silent -l {installDir}"); | ||
} | ||
|
||
/// <summary> | ||
/// Tear down. | ||
/// </summary> | ||
[OneTimeTearDown] | ||
public void BaseTeardown() | ||
{ | ||
TestCommon.TearDownTestSource(); | ||
WinGetSettingsHelper.ConfigureFeature("configureExport", false); | ||
TestCommon.RunAICLICommand("uninstall", "AppInstallerTest.TestPackageExport"); | ||
} | ||
|
||
/// <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("WinGetSource")); | ||
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("WinGetPackage")); | ||
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 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("WinGetSource")); | ||
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("WinGetPackage")); | ||
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}"); | ||
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("WinGetSource")); | ||
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("WinGetPackage")); | ||
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 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); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/AppInstallerCLIE2ETests/TestData/Manifests/TestExeInstallerForExport.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Id: AppInstallerTest.TestPackageExport | ||
Name: TestPackageExport | ||
Version: 1.0.0.0 | ||
Publisher: AppInstallerTest | ||
License: Test | ||
Installers: | ||
- Arch: x86 | ||
Url: https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe | ||
Sha256: <EXEHASH> | ||
InstallerType: exe | ||
ProductCode: '{92e3d4e5-6e3d-4ae4-b9f0-b7e0a5f25b91}' | ||
Switches: | ||
Custom: '/ProductID {92e3d4e5-6e3d-4ae4-b9f0-b7e0a5f25b91} /DisplayName TestPackageExport' | ||
SilentWithProgress: /exeswp | ||
Silent: /exesilent | ||
Interactive: /exeinteractive | ||
Language: /exeenus | ||
Log: /LogFile <LOGPATH> | ||
InstallLocation: /InstallDir <INSTALLPATH> | ||
ManifestVersion: 0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters