Skip to content

Commit

Permalink
Create SQLiteIndexSource with bare minimum search functionality (micr…
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS authored Mar 5, 2020
1 parent 9ad1353 commit 38bc61c
Show file tree
Hide file tree
Showing 39 changed files with 1,084 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/AppInstallerCLI/AppInstallerCLI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalDependencies Condition="'$(Configuration)'=='Debug'">wininet.lib;shell32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)'=='Debug'">wininet.lib;shell32.lib;winsqlite3.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
Expand All @@ -159,7 +159,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalDependencies Condition="'$(Configuration)'=='Release'">wininet.lib;shell32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)'=='Release'">wininet.lib;shell32.lib;winsqlite3.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Commands/SearchCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace AppInstaller::CLI
std::vector<Argument> SearchCommand::GetArguments() const
{
return {
Argument{ ARG_QUERY, LOCME("The query used to search for an app"), ArgumentType::Positional, true },
Argument{ ARG_QUERY, LOCME("The query used to search for an app"), ArgumentType::Positional, false },
Argument{ ARG_ID, LOCME("If specified, filter the results by id"), ArgumentType::Standard },
Argument{ ARG_NAME, LOCME("If specified, filter the results by name"), ArgumentType::Standard },
Argument{ ARG_MONIKER, LOCME("If specified, filter the results by app moniker"), ArgumentType::Standard },
Expand Down
4 changes: 3 additions & 1 deletion src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ namespace AppInstaller::Workflow

if (match.MatchCriteria.Field != ApplicationMatchField::Id && match.MatchCriteria.Field != ApplicationMatchField::Name)
{
msg += ", [" + ApplicationMatchFieldToString(match.MatchCriteria.Field) + ": " + match.MatchCriteria.Value + "]";
msg += ", [";
msg += ApplicationMatchFieldToString(match.MatchCriteria.Field);
msg += ": " + match.MatchCriteria.Value + "]";
}

m_reporter.ShowMsg(WorkflowReporter::Level::Info, msg);
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Workflows/WorkflowBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace AppInstaller::Workflow

void ReportSearchResult();

std::unique_ptr<AppInstaller::Repository::ISource> m_source;
std::shared_ptr<AppInstaller::Repository::ISource> m_source;
AppInstaller::Repository::SearchResult m_searchResult;
};
}
1 change: 1 addition & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<ClCompile Include="Downloader.cpp" />
<ClCompile Include="MsixInfo.cpp" />
<ClCompile Include="PreIndexedPackageSource.cpp" />
<ClCompile Include="SQLiteIndexSource.cpp" />
<ClCompile Include="WorkFlow.cpp" />
<ClCompile Include="LanguageUtilities.cpp" />
<ClCompile Include="main.cpp">
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<ClCompile Include="PreIndexedPackageSource.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SQLiteIndexSource.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down
174 changes: 164 additions & 10 deletions src/AppInstallerCLITests/SQLiteIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,29 @@
using namespace std::string_literals;
using namespace TestCommon;
using namespace AppInstaller::Manifest;
using namespace AppInstaller::Repository;
using namespace AppInstaller::Repository::Microsoft;
using namespace AppInstaller::Repository::SQLite;

SQLiteIndex SimpleTestSetup(const std::string& filePath, Manifest& manifest, std::string& relativePath)
{
SQLiteIndex index = SQLiteIndex::CreateNew(filePath, Schema::Version::Latest());

manifest.Id = "test.id";
manifest.Name = "Test Name";
manifest.AppMoniker = "testmoniker";
manifest.Version = "1.0.0";
manifest.Channel = "test";
manifest.Tags = { "t1", "t2" };
manifest.Commands = { "test1", "test2" };

relativePath = "test/id/1.0.0.yml";

index.AddManifest(manifest, relativePath);

return index;
}

TEST_CASE("SQLiteIndexCreateLatestAndReopen", "[sqliteindex]")
{
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
Expand Down Expand Up @@ -65,18 +85,10 @@ TEST_CASE("SQLiteIndexCreateAndAddManifest", "[sqliteindex]")
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
INFO("Using temporary file named: " << tempFile.GetPath());

SQLiteIndex index = SQLiteIndex::CreateNew(tempFile, Schema::Version::Latest());

Manifest manifest;
manifest.Id = "test.id";
manifest.Name = "Test Name";
manifest.AppMoniker = "testmoniker";
manifest.Version = "1.0.0";
manifest.Channel = "test";
manifest.Tags = { "t1", "t2" };
manifest.Commands = { "test1", "test2" };
std::string relativePath;

index.AddManifest(manifest, "test/id/test.id-1.0.0.yml");
SQLiteIndex index = SimpleTestSetup(tempFile, manifest, relativePath);
}

TEST_CASE("SQLiteIndexCreateAndAddManifestFile", "[sqliteindex]")
Expand Down Expand Up @@ -463,3 +475,145 @@ TEST_CASE("SQLiteIndex_PrepareForPackaging", "[sqliteindex]")

index.PrepareForPackaging();
}

TEST_CASE("SQLiteIndex_Search_IdExactMatch", "[sqliteindex]")
{
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
INFO("Using temporary file named: " << tempFile.GetPath());

Manifest manifest;
std::string relativePath;
SQLiteIndex index = SimpleTestSetup(tempFile, manifest, relativePath);

SearchRequest request;
request.Query = RequestMatch(MatchType::Exact, manifest.Id);

auto results = index.Search(request);
REQUIRE(results.size() == 1);
REQUIRE(results[0].second.Field == ApplicationMatchField::Id);
REQUIRE(results[0].second.Type == MatchType::Exact);
REQUIRE(results[0].second.Value == manifest.Id);
}

TEST_CASE("SQLiteIndex_Search_MultipleMatch", "[sqliteindex]")
{
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
INFO("Using temporary file named: " << tempFile.GetPath());

Manifest manifest;
std::string relativePath;
SQLiteIndex index = SimpleTestSetup(tempFile, manifest, relativePath);

manifest.Version = "2.0.0";
index.AddManifest(manifest, relativePath + "2");

SearchRequest request;
request.Query = RequestMatch(MatchType::Exact, manifest.Id);

auto results = index.Search(request);
REQUIRE(results.size() == 1);

auto result = index.GetVersionsById(results[0].first);
REQUIRE(result.size() == 2);
}

TEST_CASE("SQLiteIndex_Search_NoMatch", "[sqliteindex]")
{
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
INFO("Using temporary file named: " << tempFile.GetPath());

Manifest manifest;
std::string relativePath;
SQLiteIndex index = SimpleTestSetup(tempFile, manifest, relativePath);

SearchRequest request;
request.Query = RequestMatch(MatchType::Exact, "THIS DOES NOT MATCH ANYTHING!");

auto results = index.Search(request);
REQUIRE(results.size() == 0);
}

TEST_CASE("SQLiteIndex_IdString", "[sqliteindex]")
{
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
INFO("Using temporary file named: " << tempFile.GetPath());

Manifest manifest;
std::string relativePath;
SQLiteIndex index = SimpleTestSetup(tempFile, manifest, relativePath);

SearchRequest request;
request.Query = RequestMatch(MatchType::Exact, manifest.Id);

auto results = index.Search(request);
REQUIRE(results.size() == 1);

auto result = index.GetIdStringById(results[0].first);
REQUIRE(result.has_value());
REQUIRE(result.value() == manifest.Id);
}

TEST_CASE("SQLiteIndex_NameString", "[sqliteindex]")
{
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
INFO("Using temporary file named: " << tempFile.GetPath());

Manifest manifest;
std::string relativePath;
SQLiteIndex index = SimpleTestSetup(tempFile, manifest, relativePath);

SearchRequest request;
request.Query = RequestMatch(MatchType::Exact, manifest.Id);

auto results = index.Search(request);
REQUIRE(results.size() == 1);

auto result = index.GetNameStringById(results[0].first);
REQUIRE(result.has_value());
REQUIRE(result.value() == manifest.Name);
}

TEST_CASE("SQLiteIndex_PathString", "[sqliteindex]")
{
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
INFO("Using temporary file named: " << tempFile.GetPath());

Manifest manifest;
std::string relativePath;
SQLiteIndex index = SimpleTestSetup(tempFile, manifest, relativePath);

SearchRequest request;
request.Query = RequestMatch(MatchType::Exact, manifest.Id);

auto results = index.Search(request);
REQUIRE(results.size() == 1);

auto specificResult = index.GetPathStringByKey(results[0].first, manifest.Version, manifest.Channel);
REQUIRE(specificResult.has_value());
REQUIRE(specificResult.value() == relativePath);

auto latestResult = index.GetPathStringByKey(results[0].first, "", manifest.Channel);
REQUIRE(latestResult.has_value());
REQUIRE(latestResult.value() == relativePath);
}

TEST_CASE("SQLiteIndex_Versions", "[sqliteindex]")
{
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s };
INFO("Using temporary file named: " << tempFile.GetPath());

Manifest manifest;
std::string relativePath;
SQLiteIndex index = SimpleTestSetup(tempFile, manifest, relativePath);

SearchRequest request;
request.Query = RequestMatch(MatchType::Exact, manifest.Id);

auto results = index.Search(request);
REQUIRE(results.size() == 1);

auto result = index.GetVersionsById(results[0].first);
REQUIRE(result.size() == 1);
REQUIRE(result[0].first == manifest.Version);
REQUIRE(result[0].second == manifest.Channel);
}
Loading

0 comments on commit 38bc61c

Please sign in to comment.