forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportFlow.cpp
More file actions
191 lines (167 loc) · 9.07 KB
/
Copy pathExportFlow.cpp
File metadata and controls
191 lines (167 loc) · 9.07 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "WorkflowCommon.h"
#include "TestSource.h"
#include <Commands/ExportCommand.h>
#include <winget/ManifestYamlParser.h>
using namespace TestCommon;
using namespace AppInstaller::CLI;
using namespace AppInstaller::Repository;
using namespace AppInstaller::Manifest;
using namespace AppInstaller::Manifest::YamlParser;
TEST_CASE("ExportFlow_ExportAll", "[ExportFlow][workflow]")
{
TestCommon::TempFile exportResultPath("TestExport.json");
std::ostringstream exportOutput;
TestContext context{ exportOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context, CreateTestSource({
TSR::TestInstaller_Exe,
TSR::TestInstaller_Exe_UnknownVersion,
TSR::TestInstaller_Msix,
TSR::TestInstaller_MSStore,
TSR::TestInstaller_Portable,
TSR::TestInstaller_Zip,
}));
context.Args.AddArg(Execution::Args::Type::OutputFile, exportResultPath);
ExportCommand exportCommand({});
exportCommand.Execute(context);
INFO(exportOutput.str());
// Verify contents of exported collection
const auto& exportedCollection = context.Get<Execution::Data::PackageCollection>();
REQUIRE(exportedCollection.Sources.size() == 1);
REQUIRE(exportedCollection.Sources[0].Details.Identifier == "*TestSource");
const auto& exportedPackages = exportedCollection.Sources[0].Packages;
REQUIRE(exportedPackages.size() == 6);
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestMsixInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestMSStoreInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestPortableInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestZipInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeUnknownVersion" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
}
TEST_CASE("ExportFlow_ExportAll_WithVersions", "[ExportFlow][workflow]")
{
TestCommon::TempFile exportResultPath("TestExport.json");
std::ostringstream exportOutput;
TestContext context{ exportOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context, CreateTestSource({
TSR::TestInstaller_Exe,
TSR::TestInstaller_Exe_UnknownVersion,
TSR::TestInstaller_Msix,
TSR::TestInstaller_MSStore,
TSR::TestInstaller_Portable,
TSR::TestInstaller_Zip,
}));
context.Args.AddArg(Execution::Args::Type::OutputFile, exportResultPath);
context.Args.AddArg(Execution::Args::Type::IncludeVersions);
ExportCommand exportCommand({});
exportCommand.Execute(context);
INFO(exportOutput.str());
// Verify contents of exported collection
const auto& exportedCollection = context.Get<Execution::Data::PackageCollection>();
REQUIRE(exportedCollection.Sources.size() == 1);
REQUIRE(exportedCollection.Sources[0].Details.Identifier == "*TestSource");
const auto& exportedPackages = exportedCollection.Sources[0].Packages;
REQUIRE(exportedPackages.size() == 6);
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestMsixInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestMSStoreInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestPortableInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestZipInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeUnknownVersion" && p.VersionAndChannel.GetVersion().ToString() == "unknown";
}));
}
TEST_CASE("ExportFlow_ExportAll_WithUserInstallerArgs", "[ExportFlow][workflow]")
{
TestCommon::TempFile exportResultPath("TestExport.json");
std::ostringstream exportOutput;
TestContext context{ exportOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
// Create a test source with packages that have InitialOverrideArguments and InitialCustomSwitches set
auto testSource = CreateTestSource({});
TestSourceResult exeWithOverride(
"AppInstallerCliTest.TestExeInstaller"sv,
[](std::vector<ResultMatch>& matches, std::weak_ptr<const ISource> source)
{
auto manifest = YamlParser::CreateFromPath(TestDataFile("InstallFlowTest_Exe.yaml"));
auto manifest2 = YamlParser::CreateFromPath(TestDataFile("UpdateFlowTest_Exe.yaml"));
auto manifest3 = YamlParser::CreateFromPath(TestDataFile("UpdateFlowTest_Exe_2.yaml"));
auto testPackage = TestCompositePackage::Make(
manifest,
TestCompositePackage::MetadataMap
{
{ PackageVersionMetadata::InstalledType, "Exe" },
{ PackageVersionMetadata::InitialOverrideArguments, "/silent /override" },
{ PackageVersionMetadata::InitialCustomSwitches, "--custom-flag" },
},
std::vector<Manifest>{ manifest3, manifest2, manifest },
source);
for (auto& availablePackage : testPackage->Available)
{
availablePackage->IsSameOverride = [](const IPackage*, const IPackage*) { return true; };
}
matches.emplace_back(
ResultMatch(
testPackage,
PackageMatchFilter(PackageMatchField::Id, MatchType::Exact, "AppInstallerCliTest.TestExeInstaller")));
});
testSource->AddResult(exeWithOverride);
OverrideForCompositeInstalledSource(context, testSource);
context.Args.AddArg(Execution::Args::Type::OutputFile, exportResultPath);
ExportCommand exportCommand({});
exportCommand.Execute(context);
INFO(exportOutput.str());
const auto& exportedCollection = context.Get<Execution::Data::PackageCollection>();
REQUIRE(exportedCollection.Sources.size() == 1);
const auto& exportedPackages = exportedCollection.Sources[0].Packages;
REQUIRE(exportedPackages.size() == 1);
const auto& pkg = exportedPackages[0];
REQUIRE(pkg.Id == "AppInstallerCliTest.TestExeInstaller");
REQUIRE(pkg.InitialOverrideArgs == "/silent /override");
REQUIRE(pkg.InitialCustomSwitches == "--custom-flag");
// Verify the values are in the exported JSON file
std::ifstream exportFile(exportResultPath.GetPath());
Json::Value exportedJson;
exportFile >> exportedJson;
const auto& jsonPackage = exportedJson["Sources"][0]["Packages"][0];
REQUIRE(jsonPackage["InitialOverrideArguments"].asString() == "/silent /override");
REQUIRE(jsonPackage["InitialCustomSwitches"].asString() == "--custom-flag");
}