#define BOOST_TEST_MODULE MirrorSearch #include #include #include #include #include class Service : DB::PluginMock, public IceTray::DryIce { public: Service() : DB::PluginMock("MirrorSearch", {rootDir / "schema.sql", rootDir / "data.sql"}, "user=postgres") { } }; class TestClient : public IceTray::DryIceClient { public: TestClient() : s(getProxy("Search")) { } MirrorSearch::SearchPrxPtr 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_EQUAL(ss.front()->parserflags, 97); BOOST_CHECK(!ss.front()->listxpath.empty()); BOOST_CHECK(!ss.front()->urlxpath.empty()); } BOOST_AUTO_TEST_CASE(getMatches_failure) { BOOST_REQUIRE_THROW(s->getMatches("no.fixture"), MirrorSearch::CurlError); } BOOST_AUTO_TEST_CASE(getMatches_empty_response) { BOOST_REQUIRE_THROW(s->getMatches("empty"), MirrorSearch::CurlError); } BOOST_AUTO_TEST_CASE(getMatches_not_html) { BOOST_REQUIRE_THROW(s->getMatches("not"), MirrorSearch::XmlError); } 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();