|
2 | 2 | // Licensed under the MIT License. |
3 | 3 | #include "pch.h" |
4 | 4 | #include "WorkflowCommon.h" |
| 5 | +#include "TestSource.h" |
5 | 6 | #include <Commands/ExportCommand.h> |
| 7 | +#include <winget/ManifestYamlParser.h> |
6 | 8 |
|
7 | 9 | using namespace TestCommon; |
8 | 10 | using namespace AppInstaller::CLI; |
| 11 | +using namespace AppInstaller::Repository; |
| 12 | +using namespace AppInstaller::Manifest; |
| 13 | +using namespace AppInstaller::Manifest::YamlParser; |
9 | 14 |
|
10 | 15 | TEST_CASE("ExportFlow_ExportAll", "[ExportFlow][workflow]") |
11 | 16 | { |
@@ -115,3 +120,72 @@ TEST_CASE("ExportFlow_ExportAll_WithVersions", "[ExportFlow][workflow]") |
115 | 120 | return p.Id == "AppInstallerCliTest.TestExeUnknownVersion" && p.VersionAndChannel.GetVersion().ToString() == "unknown"; |
116 | 121 | })); |
117 | 122 | } |
| 123 | + |
| 124 | +TEST_CASE("ExportFlow_ExportAll_WithUserInstallerArgs", "[ExportFlow][workflow]") |
| 125 | +{ |
| 126 | + TestCommon::TempFile exportResultPath("TestExport.json"); |
| 127 | + |
| 128 | + std::ostringstream exportOutput; |
| 129 | + TestContext context{ exportOutput, std::cin }; |
| 130 | + auto previousThreadGlobals = context.SetForCurrentThread(); |
| 131 | + |
| 132 | + // Create a test source with packages that have InitialOverrideArguments and InitialCustomSwitches set |
| 133 | + auto testSource = CreateTestSource({}); |
| 134 | + |
| 135 | + TestSourceResult exeWithOverride( |
| 136 | + "AppInstallerCliTest.TestExeInstaller"sv, |
| 137 | + [](std::vector<ResultMatch>& matches, std::weak_ptr<const ISource> source) |
| 138 | + { |
| 139 | + auto manifest = YamlParser::CreateFromPath(TestDataFile("InstallFlowTest_Exe.yaml")); |
| 140 | + auto manifest2 = YamlParser::CreateFromPath(TestDataFile("UpdateFlowTest_Exe.yaml")); |
| 141 | + auto manifest3 = YamlParser::CreateFromPath(TestDataFile("UpdateFlowTest_Exe_2.yaml")); |
| 142 | + |
| 143 | + auto testPackage = TestCompositePackage::Make( |
| 144 | + manifest, |
| 145 | + TestCompositePackage::MetadataMap |
| 146 | + { |
| 147 | + { PackageVersionMetadata::InstalledType, "Exe" }, |
| 148 | + { PackageVersionMetadata::InitialOverrideArguments, "/silent /override" }, |
| 149 | + { PackageVersionMetadata::InitialCustomSwitches, "--custom-flag" }, |
| 150 | + }, |
| 151 | + std::vector<Manifest>{ manifest3, manifest2, manifest }, |
| 152 | + source); |
| 153 | + for (auto& availablePackage : testPackage->Available) |
| 154 | + { |
| 155 | + availablePackage->IsSameOverride = [](const IPackage*, const IPackage*) { return true; }; |
| 156 | + } |
| 157 | + matches.emplace_back( |
| 158 | + ResultMatch( |
| 159 | + testPackage, |
| 160 | + PackageMatchFilter(PackageMatchField::Id, MatchType::Exact, "AppInstallerCliTest.TestExeInstaller"))); |
| 161 | + }); |
| 162 | + |
| 163 | + testSource->AddResult(exeWithOverride); |
| 164 | + |
| 165 | + OverrideForCompositeInstalledSource(context, testSource); |
| 166 | + context.Args.AddArg(Execution::Args::Type::OutputFile, exportResultPath); |
| 167 | + |
| 168 | + ExportCommand exportCommand({}); |
| 169 | + exportCommand.Execute(context); |
| 170 | + INFO(exportOutput.str()); |
| 171 | + |
| 172 | + const auto& exportedCollection = context.Get<Execution::Data::PackageCollection>(); |
| 173 | + REQUIRE(exportedCollection.Sources.size() == 1); |
| 174 | + |
| 175 | + const auto& exportedPackages = exportedCollection.Sources[0].Packages; |
| 176 | + REQUIRE(exportedPackages.size() == 1); |
| 177 | + |
| 178 | + const auto& pkg = exportedPackages[0]; |
| 179 | + REQUIRE(pkg.Id == "AppInstallerCliTest.TestExeInstaller"); |
| 180 | + REQUIRE(pkg.InitialOverrideArgs == "/silent /override"); |
| 181 | + REQUIRE(pkg.InitialCustomSwitches == "--custom-flag"); |
| 182 | + |
| 183 | + // Verify the values are in the exported JSON file |
| 184 | + std::ifstream exportFile(exportResultPath.GetPath()); |
| 185 | + Json::Value exportedJson; |
| 186 | + exportFile >> exportedJson; |
| 187 | + |
| 188 | + const auto& jsonPackage = exportedJson["Sources"][0]["Packages"][0]; |
| 189 | + REQUIRE(jsonPackage["InitialOverrideArguments"].asString() == "/silent /override"); |
| 190 | + REQUIRE(jsonPackage["InitialCustomSwitches"].asString() == "--custom-flag"); |
| 191 | +} |
0 commit comments