summaryrefslogtreecommitdiff
path: root/service/test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'service/test.cpp')
-rw-r--r--service/test.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/service/test.cpp b/service/test.cpp
new file mode 100644
index 0000000..c115712
--- /dev/null
+++ b/service/test.cpp
@@ -0,0 +1,77 @@
+#define BOOST_TEST_MODULE MirrorSearch
+#include <boost/test/unit_test.hpp>
+
+#include <pq-mock.h>
+#include <dryice.h>
+#include <definedDirs.h>
+#include <api.h>
+
+class Service : PQ::Mock, public IceTray::DryIce {
+ public:
+ Service() : PQ::Mock("user=postgres", "MirrorSearch", {
+ rootDir / "schema.sql",
+ rootDir / "data.sql"
+ }) { }
+
+};
+
+class TestClient : public IceTray::DryIceClient {
+ public:
+ TestClient() :
+ s(getProxy<MirrorSearch::SearchPrx>("Search"))
+ {
+ }
+
+ MirrorSearch::SearchPrx s;
+};
+
+BOOST_TEST_GLOBAL_FIXTURE(Service);
+
+BOOST_FIXTURE_TEST_SUITE(tc, TestClient);
+
+BOOST_AUTO_TEST_CASE(sanity)
+{
+ BOOST_REQUIRE(s);
+ s->ice_ping();
+}
+
+BOOST_AUTO_TEST_CASE(getServices)
+{
+ auto ss = s->getServices();
+ BOOST_REQUIRE_EQUAL(ss.size(), 1);
+ BOOST_CHECK_EQUAL(ss.front()->id, 1);
+ BOOST_CHECK_EQUAL(ss.front()->name, "file searching mock");
+ BOOST_CHECK_NE(ss.front()->baseurl, "file://$SCRIPTDIR/fixtures/filesearching/%s.html");
+ BOOST_CHECK_EQUAL(ss.front()->baseurl.substr(0, 8), "file:///");
+ BOOST_CHECK(!ss.front()->listxpath.empty());
+ BOOST_CHECK(!ss.front()->urlxpath.empty());
+}
+
+BOOST_AUTO_TEST_CASE(getMatches_zstd_notfound)
+{
+ auto ms = s->getMatches("zstd-1.3.3.tar.gz");
+ BOOST_REQUIRE(ms.empty());
+}
+
+BOOST_AUTO_TEST_CASE(getMatches_xtrans)
+{
+ auto ms = s->getMatches("xtrans-1.3.5.tar.bz2");
+ BOOST_REQUIRE_EQUAL(ms.size(), 12);
+ BOOST_REQUIRE_EQUAL(ms.front()->url, "ftp://ftp.cs.mun.ca/pub/mirror/gentoo/distfiles/xtrans-1.3.5.tar.bz2");
+ BOOST_REQUIRE_EQUAL(ms.back()->url, "ftp://ftp.tr.debian.org/gentoo/distfiles/xtrans-1.3.5.tar.bz2");
+}
+
+BOOST_AUTO_TEST_CASE(getMatches_zstd_notfound_lucky)
+{
+ BOOST_REQUIRE(!s->feelingLucky("zstd-1.3.3.tar.gz"));
+}
+
+BOOST_AUTO_TEST_CASE(getMatches_xtrans_lucky)
+{
+ auto fl = s->feelingLucky("xtrans-1.3.5.tar.bz2");
+ BOOST_REQUIRE(fl);
+ BOOST_REQUIRE_EQUAL(*fl, "ftp://ftp.cs.mun.ca/pub/mirror/gentoo/distfiles/xtrans-1.3.5.tar.bz2");
+}
+
+BOOST_AUTO_TEST_SUITE_END();
+