-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The beginning of tracking packages installed by winget specifically. This adds the infrastructure to create a local index of installed packages per source, as well as the workflow updates to write installs, upgrades, and uninstalls. Future work will leverage this data to better correlate installed packages with their source.
- Loading branch information
Showing
43 changed files
with
1,068 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
#include "pch.h" | ||
#include "TestCommon.h" | ||
#include <Microsoft/SQLiteIndexSource.h> | ||
#include <winget/ManifestYamlParser.h> | ||
#include <winget/PackageTrackingCatalog.h> | ||
|
||
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; | ||
using namespace AppInstaller::Utility; | ||
|
||
static std::shared_ptr<SQLiteIndexSource> SimpleTestSetup(const std::string& filePath, SourceDetails& details, Manifest& manifest, std::string& relativePath) | ||
{ | ||
SQLiteIndex index = SQLiteIndex::CreateNew(filePath, Schema::Version::Latest()); | ||
|
||
TestDataFile testManifest("Manifest-Good.yaml"); | ||
manifest = YamlParser::CreateFromPath(testManifest); | ||
|
||
relativePath = testManifest.GetPath().filename().u8string(); | ||
|
||
index.AddManifest(manifest, relativePath); | ||
|
||
details.Name = "TestName"; | ||
details.Type = "TestType"; | ||
details.Arg = testManifest.GetPath().parent_path().u8string(); | ||
details.Data = ""; | ||
|
||
auto result = std::make_shared<SQLiteIndexSource>(details, "*SimpleTestSetup", std::move(index)); | ||
|
||
PackageTrackingCatalog::RemoveForSource(result->GetIdentifier()); | ||
|
||
return result; | ||
} | ||
|
||
TEST_CASE("TrackingCatalog_Create", "[tracking_catalog]") | ||
{ | ||
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s }; | ||
INFO("Using temporary file named: " << tempFile.GetPath()); | ||
|
||
SourceDetails details; | ||
Manifest manifest; | ||
std::string relativePath; | ||
std::shared_ptr<SQLiteIndexSource> source = SimpleTestSetup(tempFile, details, manifest, relativePath); | ||
|
||
PackageTrackingCatalog catalog = PackageTrackingCatalog::CreateForSource(source); | ||
} | ||
|
||
TEST_CASE("TrackingCatalog_Install", "[tracking_catalog]") | ||
{ | ||
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s }; | ||
INFO("Using temporary file named: " << tempFile.GetPath()); | ||
|
||
SourceDetails details; | ||
Manifest manifest; | ||
std::string relativePath; | ||
std::shared_ptr<SQLiteIndexSource> source = SimpleTestSetup(tempFile, details, manifest, relativePath); | ||
|
||
PackageTrackingCatalog catalog = PackageTrackingCatalog::CreateForSource(source); | ||
|
||
SearchRequest request; | ||
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, manifest.Id); | ||
|
||
SearchResult resultBefore = catalog.Search(request); | ||
REQUIRE(resultBefore.Matches.size() == 0); | ||
|
||
catalog.RecordInstall(manifest, manifest.Installers[0], false); | ||
|
||
SearchResult resultAfter = catalog.Search(request); | ||
REQUIRE(resultAfter.Matches.size() == 1); | ||
|
||
auto trackingVersion = resultAfter.Matches[0].Package->GetLatestAvailableVersion(); | ||
REQUIRE(trackingVersion); | ||
|
||
auto metadata = trackingVersion->GetMetadata(); | ||
REQUIRE(metadata.find(PackageVersionMetadata::TrackingWriteTime) != metadata.end()); | ||
} | ||
|
||
TEST_CASE("TrackingCatalog_Reinstall", "[tracking_catalog]") | ||
{ | ||
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s }; | ||
INFO("Using temporary file named: " << tempFile.GetPath()); | ||
|
||
SourceDetails details; | ||
Manifest manifest; | ||
std::string relativePath; | ||
std::shared_ptr<SQLiteIndexSource> source = SimpleTestSetup(tempFile, details, manifest, relativePath); | ||
|
||
PackageTrackingCatalog catalog = PackageTrackingCatalog::CreateForSource(source); | ||
|
||
SearchRequest request; | ||
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, manifest.Id); | ||
|
||
catalog.RecordInstall(manifest, manifest.Installers[0], false); | ||
|
||
SearchResult resultBefore = catalog.Search(request); | ||
REQUIRE(resultBefore.Matches.size() == 1); | ||
REQUIRE(resultBefore.Matches[0].Package->GetLatestAvailableVersion()->GetProperty(PackageVersionProperty::Name) == | ||
manifest.DefaultLocalization.Get<Localization::PackageName>()); | ||
|
||
// Change name | ||
std::string newName = "New Package Name"; | ||
manifest.DefaultLocalization.Add<Localization::PackageName>(newName); | ||
|
||
catalog.RecordInstall(manifest, manifest.Installers[0], false); | ||
|
||
SearchResult resultAfter = catalog.Search(request); | ||
REQUIRE(resultAfter.Matches.size() == 1); | ||
REQUIRE(resultBefore.Matches[0].Package->GetLatestAvailableVersion()->GetProperty(PackageVersionProperty::Name) == | ||
newName); | ||
} | ||
|
||
TEST_CASE("TrackingCatalog_Upgrade", "[tracking_catalog]") | ||
{ | ||
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s }; | ||
INFO("Using temporary file named: " << tempFile.GetPath()); | ||
|
||
SourceDetails details; | ||
Manifest manifest; | ||
std::string relativePath; | ||
std::shared_ptr<SQLiteIndexSource> source = SimpleTestSetup(tempFile, details, manifest, relativePath); | ||
|
||
PackageTrackingCatalog catalog = PackageTrackingCatalog::CreateForSource(source); | ||
|
||
SearchRequest request; | ||
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, manifest.Id); | ||
|
||
catalog.RecordInstall(manifest, manifest.Installers[0], false); | ||
|
||
SearchResult resultBefore = catalog.Search(request); | ||
REQUIRE(resultBefore.Matches.size() == 1); | ||
REQUIRE(resultBefore.Matches[0].Package->GetLatestAvailableVersion()->GetProperty(PackageVersionProperty::Version) == | ||
manifest.Version); | ||
|
||
// Change name | ||
manifest.Version = "99.1.2.3"; | ||
|
||
catalog.RecordInstall(manifest, manifest.Installers[0], true); | ||
|
||
SearchResult resultAfter = catalog.Search(request); | ||
REQUIRE(resultAfter.Matches.size() == 1); | ||
REQUIRE(resultBefore.Matches[0].Package->GetLatestAvailableVersion()->GetProperty(PackageVersionProperty::Version) == | ||
manifest.Version); | ||
} | ||
|
||
TEST_CASE("TrackingCatalog_Uninstall", "[tracking_catalog]") | ||
{ | ||
TempFile tempFile{ "repolibtest_tempdb"s, ".db"s }; | ||
INFO("Using temporary file named: " << tempFile.GetPath()); | ||
|
||
SourceDetails details; | ||
Manifest manifest; | ||
std::string relativePath; | ||
std::shared_ptr<SQLiteIndexSource> source = SimpleTestSetup(tempFile, details, manifest, relativePath); | ||
|
||
PackageTrackingCatalog catalog = PackageTrackingCatalog::CreateForSource(source); | ||
|
||
SearchRequest request; | ||
request.Filters.emplace_back(PackageMatchField::Id, MatchType::Exact, manifest.Id); | ||
|
||
catalog.RecordInstall(manifest, manifest.Installers[0], false); | ||
|
||
SearchResult resultBefore = catalog.Search(request); | ||
REQUIRE(resultBefore.Matches.size() == 1); | ||
|
||
catalog.RecordUninstall(LocIndString{ manifest.Id }); | ||
|
||
SearchResult resultAfter = catalog.Search(request); | ||
REQUIRE(resultAfter.Matches.size() == 0); | ||
} |
Oops, something went wrong.