diff options
Diffstat (limited to 'gentoobrowse-api/unittests/testMaintenance.cpp')
-rw-r--r-- | gentoobrowse-api/unittests/testMaintenance.cpp | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp index 1e3ae8e..0b451ca 100644 --- a/gentoobrowse-api/unittests/testMaintenance.cpp +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -8,9 +8,6 @@ #include <git2.h> #include <fstream> #include <maintenanceimpl.h> -#include <sql/maintenance/gitListCreateRaw.sql.h> -#include <sql/maintenance/gitListCreate.sql.h> -#include <sql/maintenance/gitListCreateIdx.sql.h> class MaintenanceClientCombined : public Maintenance, public TestClient { }; @@ -75,31 +72,23 @@ class M2 : public Gentoo::Service::Maintenance { M2(IceTray::DatabasePoolPtr d) : Gentoo::Service::Maintenance(d) { - auto dbc = db->get(); - DB::TransactionScope tx(dbc.get()); - updateFileTypes(dbc.get()); } - void applyDiffOfFolders(int64_t repoId, const boost::filesystem::path & from, const boost::filesystem::path & to) const + void applyDiffOfFolders(const boost::filesystem::path & from, const boost::filesystem::path & to) const { auto dbc = db->get(); auto fromFiles = fileSet(from); auto toFiles = fileSet(to); dbc->execute("SET search_path = gentoobrowse, pg_catalog"); - Gentoo::Service::sql::maintenance::gitListCreateRaw.modify(dbc.get())->execute(); - auto ins = dbc->modify("INSERT INTO filelistraw(repoid, status, filename) VALUES(?, ?, ?)"); - ins->bindParamI(0, repoId); - newFiles(ins, fromFiles, toFiles); - removedFiles(ins, fromFiles, toFiles); - changedFiles(ins, fromFiles, toFiles); - Gentoo::Service::sql::maintenance::gitListCreate.modify(dbc.get())->execute(); - Gentoo::Service::sql::maintenance::gitListCreateIdx.modify(dbc.get())->execute(); + DB::TransactionScope tx(dbc.get()); + Gentoo::Service::ChangeSet changes; + newFiles(changes, fromFiles, toFiles); + removedFiles(changes, fromFiles, toFiles); + changedFiles(changes, fromFiles, toFiles); boost::filesystem::remove(treeDir); boost::filesystem::create_symlink(to, treeDir); - applyFileChanges(dbc.get(), "/"); + applyFileChanges(dbc.get(), 1, "/", to, changes); boost::filesystem::remove(treeDir); - dbc->execute("DROP TABLE filelist"); - dbc->execute("DROP TABLE filelistraw"); dbc->execute("SET search_path = public, pg_catalog"); } @@ -113,34 +102,38 @@ class M2 : public Gentoo::Service::Maintenance { } return found; } - static void newFiles(DB::ModifyCommandPtr ins, const FileMap & from, const FileMap & to) + + static Gentoo::Service::PathParts split(const boost::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) { - ins->bindParamS(1, "A"); for(const auto & f : to) { if (from.find(f.first) == from.end()) { - ins->bindParamS(2, f.first.string()); - ins->execute(); + changes[f.first] = { split(f.first), GIT_DELTA_ADDED }; } } } - static void removedFiles(DB::ModifyCommandPtr ins, const FileMap & from, const FileMap & to) + static void removedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to) { - ins->bindParamS(1, "D"); for(const auto & f : from) { if (to.find(f.first) == to.end()) { - ins->bindParamS(2, f.first.string()); - ins->execute(); + changes[f.first] = { split(f.first), GIT_DELTA_DELETED }; } } } - static void changedFiles(DB::ModifyCommandPtr ins, const FileMap & from, const FileMap & to) + static void changedFiles(Gentoo::Service::ChangeSet & changes, const FileMap & from, const FileMap & to) { - ins->bindParamS(1, "M"); for(const auto & f : to) { auto i = from.find(f.first); if (i != from.end() && i->second != f.second) { - ins->bindParamS(2, f.first.string()); - ins->execute(); + changes[f.first] = { split(f.first), GIT_DELTA_MODIFIED }; } } } @@ -172,19 +165,19 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) M2 m2(p); BOOST_TEST_CONTEXT("4156eb45cf3b0ce1d7125b84efd8688c2d6e831d") { - m2.applyDiffOfFolders(1, binDir / "empty", rootDir / "fixtures" / "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); } BOOST_TEST_CONTEXT("756569aa764177340726dd3d40b41d89b11b20c7") { - m2.applyDiffOfFolders(1, rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d", rootDir / "fixtures" / "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); } BOOST_TEST_CONTEXT("empty") { - m2.applyDiffOfFolders(1, rootDir / "fixtures" / "756569aa764177340726dd3d40b41d89b11b20c7", binDir / "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); } |