diff options
Diffstat (limited to 'gentoobrowse-api/unittests/testMaintenance.cpp')
-rw-r--r-- | gentoobrowse-api/unittests/testMaintenance.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp new file mode 100644 index 0000000..c39b9af --- /dev/null +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -0,0 +1,116 @@ +#define BOOST_TEST_MODULE TestMaintenance +#include <boost/test/unit_test.hpp> + +#include "mockDefs.h" +#include <definedDirs.h> +#include <buffer.h> +#include <modifycommand.h> + +BOOST_GLOBAL_FIXTURE( Maintenance ); + +const boost::filesystem::path treeDir(binDir / "tree" / "gentoobrowse"); +const boost::filesystem::path fixturesDir(rootDir / "fixtures"); + +class SampleData { + public: + SampleData() + { + clean(); + } + + ~SampleData() + { + clean(); + } + + void clean() + { + BOOST_TEST_CHECKPOINT("Cleaning sample data dir " << treeDir); + boost::filesystem::remove_all(treeDir); + } + + void extract(const std::string & archive, const std::string & repo) + { + boost::filesystem::create_directories(treeDir); + boost::filesystem::create_symlink(fixturesDir / archive, treeDir / repo); + } +}; + +BOOST_FIXTURE_TEST_SUITE(tp, TestClient) + +void +doRefreshPackageTree(SampleData & sd, DB::ConnectionPtr db, const std::string & archive, const std::string & dir, + Gentoo::MaintenancePrx m, int64_t files, int64_t cats, int64_t devvcs, int64_t pkgs, int64_t ebs, int64_t ebus, + int64_t ebas, int64_t pus, int64_t ug, int64_t ul, int64_t ugs, int64_t ugds, int64_t deps, int64_t rdeps) +{ + if (!archive.empty()) { + sd.extract(archive, dir); + } + m->refreshPackageTree(); + sd.clean(); + + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.files", int64_t, files); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories", int64_t, cats); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories WHERE name = 'dev-vcs'", int64_t, devvcs); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.packages", int64_t, pkgs); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.ebuilds", int64_t, ebs); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.ebuild_uses", int64_t, ebus); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.ebuild_archs", int64_t, ebas); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.package_urls", int64_t, pus); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.use_global", int64_t, ug); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.use_local", int64_t, ul); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.use_groups", int64_t, ugs); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.use_group", int64_t, ugds); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.ebuild_deps", int64_t, deps); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.ebuild_rdeps", int64_t, rdeps); +} + +BOOST_AUTO_TEST_CASE( refreshPackageTree ) +{ + SampleData sd; + auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI")); + auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path) VALUES(?, ?)"); + insRepo->bindParamS(0, "gentoo"); + insRepo->bindParamS(1, (treeDir / "gentoo").string()); + insRepo->execute(); + + doRefreshPackageTree(sd, db, "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d", "gentoo", + m, 2084, 5, 1, 482, 981, 3626, 4593, 501, 393, 238, 50, 1573, 2008, 1543); + + db->execute("COPY gentoobrowse.files TO '/tmp/files1.tsv'"); + db->execute("COPY gentoobrowse.categories TO '/tmp/categories1.tsv'"); + db->execute("COPY gentoobrowse.packages TO '/tmp/packages1.tsv'"); + db->execute("COPY gentoobrowse.ebuilds TO '/tmp/ebuilds1.tsv'"); + db->execute("COPY gentoobrowse.ebuild_uses TO '/tmp/ebuild_uses1.tsv'"); + db->execute("COPY gentoobrowse.ebuild_archs TO '/tmp/ebuild_archs1.tsv'"); + db->execute("COPY gentoobrowse.package_urls TO '/tmp/package_urls1.tsv'"); + db->execute("COPY gentoobrowse.use_global TO '/tmp/use_global1.tsv'"); + db->execute("COPY gentoobrowse.use_local TO '/tmp/use_local1.tsv'"); + db->execute("COPY gentoobrowse.use_groups TO '/tmp/use_groups1.tsv'"); + db->execute("COPY gentoobrowse.use_group TO '/tmp/use_group1.tsv'"); + db->execute("COPY gentoobrowse.masksets TO '/tmp/masksets1.tsv'"); + db->execute("COPY gentoobrowse.ebuild_masks TO '/tmp/ebuild_masks1.tsv'"); + + doRefreshPackageTree(sd, db, "756569aa764177340726dd3d40b41d89b11b20c7", "gentoo", + m, 2087, 5, 1, 484, 982, 3638, 4599, 503, 393, 238, 50, 1573, 2009, 1546); + + db->execute("COPY gentoobrowse.categories TO '/tmp/categories2.tsv'"); + db->execute("COPY gentoobrowse.packages TO '/tmp/packages2.tsv'"); + db->execute("COPY gentoobrowse.ebuilds TO '/tmp/ebuilds2.tsv'"); + db->execute("COPY gentoobrowse.ebuild_uses TO '/tmp/ebuild_uses2.tsv'"); + db->execute("COPY gentoobrowse.ebuild_archs TO '/tmp/ebuild_archs2.tsv'"); + db->execute("COPY gentoobrowse.package_urls TO '/tmp/package_urls2.tsv'"); + db->execute("COPY gentoobrowse.use_global TO '/tmp/use_global2.tsv'"); + db->execute("COPY gentoobrowse.use_local TO '/tmp/use_local2.tsv'"); + db->execute("COPY gentoobrowse.use_groups TO '/tmp/use_groups2.tsv'"); + db->execute("COPY gentoobrowse.use_group TO '/tmp/use_group2.tsv'"); + db->execute("COPY gentoobrowse.masksets TO '/tmp/masksets2.tsv'"); + db->execute("COPY gentoobrowse.ebuild_masks TO '/tmp/ebuild_masks2.tsv'"); + + doRefreshPackageTree(sd, db, "", "gentoo", + m, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + m->refreshPackageTree(); +} + +BOOST_AUTO_TEST_SUITE_END(); + |