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.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp
index 015a596..1ee94bc 100644
--- a/gentoobrowse-api/unittests/testMaintenance.cpp
+++ b/gentoobrowse-api/unittests/testMaintenance.cpp
@@ -5,6 +5,7 @@
#include <definedDirs.h>
#include <buffer.h>
#include <modifycommand.h>
+#include <git2.h>
class MaintenanceClientCombined : public Maintenance, public TestClient { };
@@ -114,5 +115,61 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
m, 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)
+{
+ git_signature * sig;
+ git_index * index;
+ git_oid tree_id, commit_id;
+ git_tree * tree;
+
+ BOOST_REQUIRE_EQUAL(0, git_signature_default(&sig, 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));
+
+ git_index_free(index);
+ git_tree_free(tree);
+ git_signature_free(sig);
+ return commit_id;
+}
+
+BOOST_AUTO_TEST_CASE( testUpdateGitRepository )
+{
+ auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI"));
+ auto testRepo = binDir / "testrepo";
+ boost::filesystem::remove_all(testRepo);
+ boost::filesystem::create_directories(testRepo);
+ // Create a stub repo to update
+ git_libgit2_init();
+ git_repository * repo;
+ BOOST_REQUIRE_EQUAL(0, git_repository_init(&repo, testRepo.c_str(), false));
+ git_remote * origin;
+ BOOST_REQUIRE_EQUAL(0, git_remote_create(&origin, repo, "origin", "http://git.randomdan.homeip.net/git/portage"));
+ git_remote_free(origin);
+ create_initial_commit(repo);
+ git_repository_free(repo);
+ git_libgit2_shutdown();
+ // Reference it
+ auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path, upstream, branch) VALUES(?, ?, ?, ?)");
+ insRepo->bindParamS(0, "testrepo");
+ insRepo->bindParamS(1, testRepo.string());
+ insRepo->bindParamS(2, "origin");
+ insRepo->bindParamS(3, "master");
+ insRepo->execute();
+
+ // Update
+ m->updateRepositories();
+
+ // Verify checkout
+ BOOST_REQUIRE(boost::filesystem::is_directory(testRepo));
+ BOOST_REQUIRE(boost::filesystem::is_directory(testRepo / "virtual"));
+ BOOST_REQUIRE(boost::filesystem::is_directory(testRepo / "net-misc"));
+ BOOST_REQUIRE(boost::filesystem::is_directory(testRepo / "net-misc" / "gentoobrowse-api"));
+ BOOST_REQUIRE(boost::filesystem::is_regular_file(testRepo / "net-misc" / "gentoobrowse-api" / "Manifest"));
+}
+
BOOST_AUTO_TEST_SUITE_END();