summaryrefslogtreecommitdiff
path: root/gentoobrowse-api/unittests/testMaintenance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gentoobrowse-api/unittests/testMaintenance.cpp')
-rw-r--r--gentoobrowse-api/unittests/testMaintenance.cpp226
1 files changed, 125 insertions, 101 deletions
diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp
index da0e6cd..19ed59a 100644
--- a/gentoobrowse-api/unittests/testMaintenance.cpp
+++ b/gentoobrowse-api/unittests/testMaintenance.cpp
@@ -2,16 +2,17 @@
#include <boost/test/unit_test.hpp>
#include "mockDefs.h"
-#include <definedDirs.h>
#include <buffer.h>
-#include <modifycommand.h>
-#include <git2.h>
+#include <definedDirs.h>
#include <fstream>
+#include <git2.h>
#include <maintenanceimpl.h>
-#include <portageimpl.h>
#include <mockPool.h>
+#include <modifycommand.h>
+#include <portageimpl.h>
-class MaintenanceClientCombined : public Maintenance, public TestClient { };
+class MaintenanceClientCombined : public Maintenance, public TestClient {
+};
BOOST_FIXTURE_TEST_SUITE(maintenance, MaintenanceClientCombined)
@@ -68,86 +69,90 @@ dumpDb(DB::ConnectionPtr db)
}
class M2 : public Gentoo::Service::Maintenance {
- public:
- typedef std::map<std::filesystem::path, size_t> FileMap;
-
- M2(const DB::ConnectionPoolPtr & d) :
- Gentoo::Service::Maintenance(d)
- {
- }
-
- void applyDiffOfFolders(const std::filesystem::path & from, const std::filesystem::path & to) const
- {
- auto dbc = db->get();
- auto fromFiles = fileSet(from);
- auto toFiles = fileSet(to);
- DB::TransactionScope tx(*dbc.get());
- Gentoo::Service::ChangeSet changes;
- newFiles(changes, fromFiles, toFiles);
- removedFiles(changes, fromFiles, toFiles);
- changedFiles(changes, fromFiles, toFiles);
- std::filesystem::remove(treeDir);
- std::filesystem::create_symlink(to, treeDir);
- Gentoo::Repository repo = { 1, "gentoo", to.string(), "origin", "master", "" };
- applyFileChanges(dbc.get(), "/", repo, changes);
- std::filesystem::remove(treeDir);
- }
+public:
+ typedef std::map<std::filesystem::path, size_t> FileMap;
+
+ M2(const DB::ConnectionPoolPtr & d) : Gentoo::Service::Maintenance(d) { }
+
+ void
+ applyDiffOfFolders(const std::filesystem::path & from, const std::filesystem::path & to) const
+ {
+ auto dbc = db->get();
+ auto fromFiles = fileSet(from);
+ auto toFiles = fileSet(to);
+ DB::TransactionScope tx(*dbc.get());
+ Gentoo::Service::ChangeSet changes;
+ newFiles(changes, fromFiles, toFiles);
+ removedFiles(changes, fromFiles, toFiles);
+ changedFiles(changes, fromFiles, toFiles);
+ std::filesystem::remove(treeDir);
+ std::filesystem::create_symlink(to, treeDir);
+ Gentoo::Repository repo = {1, "gentoo", to.string(), "origin", "master", ""};
+ applyFileChanges(dbc.get(), "/", repo, changes);
+ std::filesystem::remove(treeDir);
+ }
- static FileMap fileSet(const std::filesystem::path & p)
- {
- FileMap found;
- for (std::filesystem::recursive_directory_iterator r(p); r != std::filesystem::recursive_directory_iterator(); r++) {
- if (std::filesystem::is_regular_file(r->status())) {
- found[std::filesystem::relative(*r, p)] = std::filesystem::file_size(*r);
- }
+ static FileMap
+ fileSet(const std::filesystem::path & p)
+ {
+ FileMap found;
+ for (std::filesystem::recursive_directory_iterator r(p); r != std::filesystem::recursive_directory_iterator();
+ r++) {
+ if (std::filesystem::is_regular_file(r->status())) {
+ found[std::filesystem::relative(*r, p)] = std::filesystem::file_size(*r);
}
- return found;
}
+ return found;
+ }
- static Gentoo::Service::PathParts split(const std::filesystem::path & path)
- {
- Gentoo::Service::PathParts pp;
- for (const auto & p : path) {
- pp.push_back(p.string());
- }
- return pp;
+ static Gentoo::Service::PathParts
+ split(const std::filesystem::path & path)
+ {
+ Gentoo::Service::PathParts pp;
+ for (const auto & p : path) {
+ pp.push_back(p.string());
}
+ return pp;
+ }
- static void newFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to)
- {
- for(const auto & f : to) {
- if (from.find(f.first) == from.end()) {
- changes[f.first] = { split(f.first), GIT_DELTA_ADDED };
- }
+ static void
+ newFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to)
+ {
+ for (const auto & f : to) {
+ if (from.find(f.first) == from.end()) {
+ changes[f.first] = {split(f.first), GIT_DELTA_ADDED};
}
}
- static void removedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to)
- {
- for(const auto & f : from) {
- if (to.find(f.first) == to.end()) {
- changes[f.first] = { split(f.first), GIT_DELTA_DELETED };
- }
+ }
+ static void
+ removedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to)
+ {
+ for (const auto & f : from) {
+ if (to.find(f.first) == to.end()) {
+ changes[f.first] = {split(f.first), GIT_DELTA_DELETED};
}
}
- static void changedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to)
- {
- for(const auto & f : to) {
- auto i = from.find(f.first);
- if (i != from.end() && i->second != f.second) {
- changes[f.first] = { split(f.first), GIT_DELTA_MODIFIED };
- }
+ }
+ static void
+ changedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to)
+ {
+ for (const auto & f : to) {
+ auto i = from.find(f.first);
+ if (i != from.end() && i->second != f.second) {
+ changes[f.first] = {split(f.first), GIT_DELTA_MODIFIED};
}
}
+ }
};
#define BOOST_TEST_CONTEXT_VAR(VAR, EXPR) \
- BOOST_TEST_CONTEXT(#EXPR) \
- for (auto VAR = EXPR, * __context__run = &VAR; __context__run; __context__run = NULL)
+ BOOST_TEST_CONTEXT(#EXPR) for (auto VAR = EXPR, *__context__run = &VAR; __context__run; __context__run = NULL)
-BOOST_AUTO_TEST_CASE( refreshPackageTree )
+BOOST_AUTO_TEST_CASE(refreshPackageTree)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI"));
- auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)");
+ auto insRepo = db->modify(
+ "INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)");
insRepo->bindParamS(0, "gentoo");
insRepo->bindParamS(1, treeDir.string());
insRepo->bindParamS(2, "origin");
@@ -162,12 +167,13 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
BOOST_TEST_CONTEXT("4156eb45cf3b0ce1d7125b84efd8688c2d6e831d") {
m2.applyDiffOfFolders(binDir / "empty", rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d");
- doRefreshPackageTree(db,
- 5, 1, 482, 981, 3626, 4593, 501, 393, 238, 50, 1573, 2008, 1543, 81, 152, 7);
+ doRefreshPackageTree(db, 5, 1, 482, 981, 3626, 4593, 501, 393, 238, 50, 1573, 2008, 1543, 81, 152, 7);
Gentoo::PortagePtr portage = std::make_shared<Gentoo::Service::Portage>(p);
- BOOST_TEST_CONTEXT_VAR(acjtr, portage->findPackage("app-crypt", "johntheripper", Ice::Current())) {
- BOOST_TEST_CONTEXT_VAR(acjtrUses, portage->getPackageUses(acjtr->packageid, Ice::Current())) {
+ BOOST_TEST_CONTEXT_VAR(acjtr, portage->findPackage("app-crypt", "johntheripper", Ice::Current()))
+ {
+ BOOST_TEST_CONTEXT_VAR(acjtrUses, portage->getPackageUses(acjtr->packageid, Ice::Current()))
+ {
BOOST_REQUIRE_EQUAL(9, acjtrUses.size());
BOOST_REQUIRE_EQUAL("custom-cflags", acjtrUses[1]->use);
BOOST_REQUIRE(!acjtrUses[1]->defaultflag);
@@ -182,8 +188,10 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
BOOST_REQUIRE_EQUAL("cpu_flags_x86", *acjtrUses[7]->group);
}
}
- BOOST_TEST_CONTEXT_VAR(nms, portage->findPackage("net-proxy", "squid", Ice::Current())) {
- BOOST_TEST_CONTEXT_VAR(nmsUses, portage->getPackageUses(nms->packageid, Ice::Current())) {
+ BOOST_TEST_CONTEXT_VAR(nms, portage->findPackage("net-proxy", "squid", Ice::Current()))
+ {
+ BOOST_TEST_CONTEXT_VAR(nmsUses, portage->getPackageUses(nms->packageid, Ice::Current()))
+ {
BOOST_REQUIRE_EQUAL(30, nmsUses.size());
BOOST_REQUIRE_EQUAL("caps", nmsUses[0]->use);
BOOST_REQUIRE(!nmsUses[0]->defaultflag);
@@ -197,21 +205,19 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
}
BOOST_TEST_CONTEXT("756569aa764177340726dd3d40b41d89b11b20c7") {
- m2.applyDiffOfFolders(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d", rootDir / "fixtures" / "756569aa764177340726dd3d40b41d89b11b20c7");
- doRefreshPackageTree(db,
- 5, 1, 483, 982, 3638, 4599, 502, 393, 238, 50, 1573, 2009, 1546, 79, 152, 10);
+ m2.applyDiffOfFolders(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d",
+ rootDir / "fixtures" / "756569aa764177340726dd3d40b41d89b11b20c7");
+ doRefreshPackageTree(db, 5, 1, 483, 982, 3638, 4599, 502, 393, 238, 50, 1573, 2009, 1546, 79, 152, 10);
}
BOOST_TEST_CONTEXT("empty") {
m2.applyDiffOfFolders(rootDir / "fixtures" / "756569aa764177340726dd3d40b41d89b11b20c7", binDir / "empty");
- doRefreshPackageTree(db,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ doRefreshPackageTree(db, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
}
-static
-git_oid
-create_initial_commit(git_repository *repo)
+static git_oid
+create_initial_commit(git_repository * repo)
{
git_signature * sig;
git_index * index;
@@ -222,7 +228,7 @@ create_initial_commit(git_repository *repo)
BOOST_REQUIRE_EQUAL(0, git_repository_index(&index, repo));
BOOST_REQUIRE_EQUAL(0, git_index_write_tree(&tree_id, index));
BOOST_REQUIRE_EQUAL(0, git_tree_lookup(&tree, repo, &tree_id));
- BOOST_REQUIRE_EQUAL(0, git_commit_create_v( &commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0));
+ BOOST_REQUIRE_EQUAL(0, git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0));
git_index_free(index);
git_tree_free(tree);
@@ -230,7 +236,7 @@ create_initial_commit(git_repository *repo)
return commit_id;
}
-BOOST_AUTO_TEST_CASE( testUpdateGitRepository )
+BOOST_AUTO_TEST_CASE(testUpdateGitRepository)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI"));
auto testRepo = binDir / "testrepo";
@@ -249,7 +255,8 @@ BOOST_AUTO_TEST_CASE( testUpdateGitRepository )
git_repository_free(repo);
git_libgit2_shutdown();
// Reference it
- auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)");
+ auto insRepo = db->modify(
+ "INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)");
insRepo->bindParamS(0, "testrepo");
insRepo->bindParamS(1, testRepo.string());
insRepo->bindParamS(2, "origin");
@@ -268,10 +275,11 @@ BOOST_AUTO_TEST_CASE( testUpdateGitRepository )
BOOST_REQUIRE(std::filesystem::is_regular_file(testRepo / "net-misc" / "gentoobrowse-api" / "Manifest"));
}
-BOOST_AUTO_TEST_CASE( testRefreshGitRepository )
+BOOST_AUTO_TEST_CASE(testRefreshGitRepository)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI"));
- auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)");
+ auto insRepo = db->modify(
+ "INSERT INTO gentoobrowse.repos(name, path, upstream, branch, lastcommit) VALUES(?, ?, ?, ?, ?)");
insRepo->bindParamS(0, "gentoo");
insRepo->bindParamS(1, "/usr/portage");
insRepo->bindParamS(2, "origin");
@@ -282,42 +290,59 @@ BOOST_AUTO_TEST_CASE( testRefreshGitRepository )
db->executeScript(data, rootDir);
BOOST_TEST_CONTEXT("Intiial values") {
- SQL_REQUIRE_EQUAL(R"SQL(SELECT name FROM gentoobrowse.packages p WHERE p.packageid = 9)SQL", std::string, "libkgapi");
+ SQL_REQUIRE_EQUAL(
+ R"SQL(SELECT name FROM gentoobrowse.packages p WHERE p.packageid = 9)SQL", std::string, "libkgapi");
SQL_REQUIRE_EQUAL(R"SQL(SELECT p.categoryid FROM gentoobrowse.categories c, gentoobrowse.packages p
- WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='net-libs')SQL", int64_t, 6);
+ WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='net-libs')SQL",
+ int64_t, 6);
SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 9)SQL", int64_t, 2);
- SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 2);
- SQL_REQUIRE_EQUAL(R"SQL(SELECT MIN(e.packageid) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 9);
+ SQL_REQUIRE_EQUAL(
+ R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 2);
+ SQL_REQUIRE_EQUAL(R"SQL(SELECT MIN(e.packageid) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL",
+ int64_t, 9);
}
// Import it
m->refreshPackageTree();
- SQL_REQUIRE_EQUAL(R"SQL(SELECT lastCommit FROM gentoobrowse.repos)SQL", std::string, "40539afe6705aee26a55bb861f5e892ae7240057");
+ SQL_REQUIRE_EQUAL(R"SQL(SELECT lastCommit FROM gentoobrowse.repos)SQL", std::string,
+ "40539afe6705aee26a55bb861f5e892ae7240057");
BOOST_TEST_CONTEXT("libkgapi was moved correctly") {
BOOST_TEST_CONTEXT("from net-libs to kde-apps") {
SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.categories c, gentoobrowse.packages p
- WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", int64_t, 1);
+ WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL",
+ int64_t, 1);
SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.categories c, gentoobrowse.packages p
- WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='net-libs')SQL", int64_t, 0);
+ WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='net-libs')SQL",
+ int64_t, 0);
}
BOOST_TEST_CONTEXT("And it was created new in the right category") {
SQL_REQUIRE_EQUAL(R"SQL(SELECT p.packageid FROM gentoobrowse.categories c, gentoobrowse.packages p
- WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", int64_t, 28);
+ WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL",
+ int64_t, 28);
SQL_REQUIRE_EQUAL(R"SQL(SELECT p.categoryid FROM gentoobrowse.categories c, gentoobrowse.packages p
- WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL", int64_t, 8);
+ WHERE c.categoryid = p.categoryid AND p.name = 'libkgapi' AND c.name='kde-apps')SQL",
+ int64_t, 8);
}
BOOST_TEST_CONTEXT("Original ebuilds in moved package were deleted") {
SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 9)SQL", int64_t, 0);
- SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 28)SQL", int64_t, 2);
- SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 0);
+ SQL_REQUIRE_EQUAL(
+ R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 28)SQL", int64_t, 2);
+ SQL_REQUIRE_EQUAL(
+ R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 0);
}
}
BOOST_TEST_CONTEXT("Change log was imported correctly") {
SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog", int64_t, 43);
- SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog WHERE commitid = 'ca4dc75c068fcffad6ff46678dfff3fcbdf8f1d2'", int64_t, 1);
- SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog WHERE commitid = '8292397bf6a8c91215b03a558e8bc843aff25b64'", int64_t, 0);
- SQL_REQUIRE_EQUAL("SELECT ARRAY_LENGTH(files, 1) FROM gentoobrowse.changelog WHERE commitid = 'ca4dc75c068fcffad6ff46678dfff3fcbdf8f1d2'", int64_t, 5);
+ SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog WHERE commitid = "
+ "'ca4dc75c068fcffad6ff46678dfff3fcbdf8f1d2'",
+ int64_t, 1);
+ SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.changelog WHERE commitid = "
+ "'8292397bf6a8c91215b03a558e8bc843aff25b64'",
+ int64_t, 0);
+ SQL_REQUIRE_EQUAL("SELECT ARRAY_LENGTH(files, 1) FROM gentoobrowse.changelog WHERE commitid = "
+ "'ca4dc75c068fcffad6ff46678dfff3fcbdf8f1d2'",
+ int64_t, 5);
#if DUMPDB
db->execute("COPY gentoobrowse.changelog TO '/tmp/changelog.tsv'");
#endif
@@ -325,4 +350,3 @@ BOOST_AUTO_TEST_CASE( testRefreshGitRepository )
}
BOOST_AUTO_TEST_SUITE_END();
-