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

Fix test task overrides #1526

Merged
merged 4 commits into from
Sep 30, 2021
Merged
Changes from 2 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
48 changes: 26 additions & 22 deletions src/AppInstallerCLITests/WorkFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ namespace
{
input = request.Inclusions[0].Value;
}
else if (!request.Filters.empty())
{
input = request.Filters[0].Value;
}

// Empty query should return all exe, msix and msstore installer
if (input.empty() || input == "AppInstallerCliTest.TestExeInstaller")
Expand Down Expand Up @@ -288,10 +292,8 @@ namespace
// Enables overriding the behavior of specific workflow tasks.
struct TestContext : public Context
{
TestContext(std::ostream& out, std::istream& in) : m_out(out), m_in(in), Context(out, in)
TestContext(std::ostream& out, std::istream& in) : TestContext(out, in, false, std::make_shared<std::vector<WorkflowTaskOverride>>())
{
m_overrides = std::make_shared<std::vector<WorkflowTaskOverride>>();

WorkflowTaskOverride wto
{ RemoveInstaller, [](TestContext&)
{
Expand All @@ -305,25 +307,7 @@ namespace
}

// For clone
TestContext(std::ostream& out, std::istream& in, std::shared_ptr<std::vector<WorkflowTaskOverride>> overrides) :
m_out(out), m_in(in), m_overrides(overrides), m_isClone(true), Context(out, in)
{
m_shouldExecuteWorkflowTask = [this](const Workflow::WorkflowTask& task)
{
auto itr = std::find_if(m_overrides->begin(), m_overrides->end(), [&](const WorkflowTaskOverride& wto) { return wto.Target == task; });

if (itr == m_overrides->end())
{
return true;
}
else
{
itr->Used = true;
itr->Override(*this);
return false;
}
};
}
TestContext(std::ostream& out, std::istream& in, std::shared_ptr<std::vector<WorkflowTaskOverride>> overrides) : TestContext(out, in, true, overrides) {}
florelis marked this conversation as resolved.
Show resolved Hide resolved

~TestContext()
{
Expand Down Expand Up @@ -352,6 +336,26 @@ namespace
}

private:
TestContext(std::ostream& out, std::istream& in, bool isClone, std::shared_ptr<std::vector<WorkflowTaskOverride>> overrides) :
m_out(out), m_in(in), m_overrides(overrides), m_isClone(isClone), Context(out, in)
{
m_shouldExecuteWorkflowTask = [this](const Workflow::WorkflowTask& task)
{
auto itr = std::find_if(m_overrides->begin(), m_overrides->end(), [&](const WorkflowTaskOverride& wto) { return wto.Target == task; });

if (itr == m_overrides->end())
{
return true;
}
else
{
itr->Used = true;
itr->Override(*this);
return false;
}
};
}

std::shared_ptr<std::vector<WorkflowTaskOverride>> m_overrides;
std::ostream& m_out;
std::istream& m_in;
Expand Down