Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test workflow source search #2782

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/AppInstallerCLITests/ExportFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ TEST_CASE("ExportFlow_ExportAll", "[ExportFlow][workflow]")
std::ostringstream exportOutput;
TestContext context{ exportOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
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({});
Expand Down Expand Up @@ -61,7 +68,14 @@ TEST_CASE("ExportFlow_ExportAll_WithVersions", "[ExportFlow][workflow]")
std::ostringstream exportOutput;
TestContext context{ exportOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
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);

Expand Down
15 changes: 12 additions & 3 deletions src/AppInstallerCLITests/ImportFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ using namespace AppInstaller::Utility::literals;

void OverrideForImportSource(TestContext& context, bool useTestCompositeSource = false)
{
auto testCompositeSource = CreateTestSource({
TSR::TestInstaller_Exe,
TSR::TestInstaller_Exe_Dependencies,
TSR::TestInstaller_Exe_LicenseAgreement,
TSR::TestInstaller_Exe_NothingInstalled,
TSR::TestInstaller_Msix,
TSR::TestInstaller_Msix_WFDependency,
});

context.Override({ "OpenPredefinedSource", [=](TestContext& context)
{
auto installedSource = useTestCompositeSource ? std::make_shared<WorkflowTestCompositeSource>() : std::make_shared<TestSource>();
auto installedSource = useTestCompositeSource ? testCompositeSource : std::make_shared<TestSource>();
context.Add<Execution::Data::Source>(Source{ installedSource });
} });

context.Override({ Workflow::OpenSourcesForImport, [](TestContext& context)
context.Override({ Workflow::OpenSourcesForImport, [=](TestContext& context)
{
context.Add<Execution::Data::Sources>(std::vector<Source>{ Source{ std::make_shared<WorkflowTestCompositeSource>() } });
context.Add<Execution::Data::Sources>(std::vector<Source>{ Source{ testCompositeSource } });
} });
}

Expand Down
10 changes: 5 additions & 5 deletions src/AppInstallerCLITests/InstallFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,9 @@ TEST_CASE("InstallFlow_SearchAndInstall", "[InstallFlow][workflow]")
std::ostringstream installOutput;
TestContext context{ installOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForOpenSource(context, true);
OverrideForOpenSource(context, CreateTestSource({ TSR::TestQuery_ReturnOne }), true);
OverrideForShellExecute(context);
context.Args.AddArg(Execution::Args::Type::Query, "TestQueryReturnOne"sv);
context.Args.AddArg(Execution::Args::Type::Query, TSR::TestQuery_ReturnOne.Query);

InstallCommand install({});
install.Execute(context);
Expand All @@ -869,7 +869,7 @@ TEST_CASE("InstallFlow_SearchFoundNoApp", "[InstallFlow][workflow]")
std::ostringstream installOutput;
TestContext context{ installOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForOpenSource(context, true);
OverrideForOpenSource(context, CreateTestSource({}), true);
context.Args.AddArg(Execution::Args::Type::Query, "TestQueryReturnZero"sv);

InstallCommand install({});
Expand All @@ -885,8 +885,8 @@ TEST_CASE("InstallFlow_SearchFoundMultipleApp", "[InstallFlow][workflow]")
std::ostringstream installOutput;
TestContext context{ installOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForOpenSource(context, true);
context.Args.AddArg(Execution::Args::Type::Query, "TestQueryReturnTwo"sv);
OverrideForOpenSource(context, CreateTestSource({ TSR::TestQuery_ReturnTwo }), true);
context.Args.AddArg(Execution::Args::Type::Query, TSR::TestQuery_ReturnTwo.Query);

InstallCommand install({});
install.Execute(context);
Expand Down
8 changes: 4 additions & 4 deletions src/AppInstallerCLITests/ShowFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ TEST_CASE("ShowFlow_SearchAndShowAppInfo", "[ShowFlow][workflow]")
std::ostringstream showOutput;
TestContext context{ showOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForOpenSource(context);
context.Args.AddArg(Execution::Args::Type::Query, "TestQueryReturnOne"sv);
OverrideForOpenSource(context, CreateTestSource({ TSR::TestQuery_ReturnOne }));
context.Args.AddArg(Execution::Args::Type::Query, TSR::TestQuery_ReturnOne.Query);

ShowCommand show({});
show.Execute(context);
Expand All @@ -32,8 +32,8 @@ TEST_CASE("ShowFlow_SearchAndShowAppVersion", "[ShowFlow][workflow]")
std::ostringstream showOutput;
TestContext context{ showOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForOpenSource(context);
context.Args.AddArg(Execution::Args::Type::Query, "TestQueryReturnOne"sv);
OverrideForOpenSource(context, CreateTestSource({ TSR::TestQuery_ReturnOne }));
context.Args.AddArg(Execution::Args::Type::Query, TSR::TestQuery_ReturnOne.Query);
context.Args.AddArg(Execution::Args::Type::ListVersions);

ShowCommand show({});
Expand Down
18 changes: 9 additions & 9 deletions src/AppInstallerCLITests/UninstallFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ TEST_CASE("UninstallFlow_UninstallPortable", "[UninstallFlow][workflow]")
std::ostringstream uninstallOutput;
TestContext context{ uninstallOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
OverrideForCompositeInstalledSource(context, CreateTestSource({ TSR::TestInstaller_Portable }));
OverrideForPortableUninstall(context);
context.Args.AddArg(Execution::Args::Type::Query, "AppInstallerCliTest.TestPortableInstaller"sv);
context.Args.AddArg(Execution::Args::Type::Query, TSR::TestInstaller_Portable.Query);

UninstallCommand uninstall({});
uninstall.Execute(context);
Expand All @@ -84,9 +84,9 @@ TEST_CASE("UninstallFlow_UninstallExe", "[UninstallFlow][workflow]")
std::ostringstream uninstallOutput;
TestContext context{ uninstallOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
OverrideForCompositeInstalledSource(context, CreateTestSource({ TSR::TestInstaller_Exe }));
OverrideForExeUninstall(context);
context.Args.AddArg(Execution::Args::Type::Query, "AppInstallerCliTest.TestExeInstaller"sv);
context.Args.AddArg(Execution::Args::Type::Query, TSR::TestInstaller_Exe.Query);
context.Args.AddArg(Execution::Args::Type::Silent);

UninstallCommand uninstall({});
Expand All @@ -110,9 +110,9 @@ TEST_CASE("UninstallFlow_UninstallMsix", "[UninstallFlow][workflow]")
std::ostringstream uninstallOutput;
TestContext context{ uninstallOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
OverrideForCompositeInstalledSource(context, CreateTestSource({ TSR::TestInstaller_Msix }));
OverrideForMSIXUninstall(context);
context.Args.AddArg(Execution::Args::Type::Query, "AppInstallerCliTest.TestMsixInstaller"sv);
context.Args.AddArg(Execution::Args::Type::Query, TSR::TestInstaller_Msix.Query);

UninstallCommand uninstall({});
uninstall.Execute(context);
Expand All @@ -134,9 +134,9 @@ TEST_CASE("UninstallFlow_UninstallMSStore", "[UninstallFlow][workflow]")
std::ostringstream uninstallOutput;
TestContext context{ uninstallOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
OverrideForCompositeInstalledSource(context, CreateTestSource({ TSR::TestInstaller_MSStore }));
OverrideForMSIXUninstall(context);
context.Args.AddArg(Execution::Args::Type::Query, "AppInstallerCliTest.TestMSStoreInstaller"sv);
context.Args.AddArg(Execution::Args::Type::Query, TSR::TestInstaller_MSStore.Query);

UninstallCommand uninstall({});
uninstall.Execute(context);
Expand All @@ -158,7 +158,7 @@ TEST_CASE("UninstallFlow_UninstallExeNotFound", "[UninstallFlow][workflow]")
std::ostringstream uninstallOutput;
TestContext context{ uninstallOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
OverrideForCompositeInstalledSource(context, CreateTestSource({}));
context.Args.AddArg(Execution::Args::Type::Query, "AppInstallerCliTest.MissingApp"sv);
context.Args.AddArg(Execution::Args::Type::Silent);

Expand Down
Loading