summaryrefslogtreecommitdiff
path: root/service/test.cpp
blob: c115712e7539fd689982d3b15385b2d71fe5301c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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();