Imported Upstream version 15.0.0
[platform/upstream/libzypp.git] / tests / parser / RepoFileReader_test.cc
1 #include <sstream>
2 #include <string>
3 #include <zypp/parser/RepoFileReader.h>
4 #include <zypp/base/NonCopyable.h>
5
6 #include "TestSetup.h"
7
8 using std::stringstream;
9 using std::string;
10 using namespace zypp;
11
12 static string suse_repo = "[factory-oss]\n"
13 "name=factory-oss\n"
14 "enabled=1\n"
15 "autorefresh=0\n"
16 "baseurl=http://download.opensuse.org/factory-tested/repo/oss/\n"
17 "type=yast2\n"
18 "keeppackages=0\n";
19
20 static string fedora_repo = "[fedora]\n"
21 "name=Fedora $releasever - $basearch\n"
22 "failovermethod=priority\n"
23 "#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/\n"
24 "#mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch\n"
25 "mirrorlist=file:///etc/yum.repos.d/local.mirror\n"
26 "enabled=1\n"
27 "gpgcheck=1\n"
28 "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY\n";
29
30 struct RepoCollector : private base::NonCopyable
31 {
32   bool collect( const RepoInfo &repo )
33   {
34     repos.push_back(repo);
35     return true;
36   }
37
38   RepoInfoList repos;
39 };
40
41 // Must be the first test!
42 BOOST_AUTO_TEST_CASE(read_repo_file)
43 {
44   {
45     stringstream input(suse_repo);
46     RepoCollector collector;
47     parser::RepoFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) );
48     BOOST_CHECK_EQUAL(1, collector.repos.size());
49   }
50   // fedora
51   {
52     stringstream input(fedora_repo);
53     RepoCollector collector;
54     parser::RepoFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) );
55     BOOST_REQUIRE_EQUAL(1, collector.repos.size());
56
57     RepoInfo repo = *collector.repos.begin();
58     // should have taken the first url if more are present
59     BOOST_CHECK_EQUAL(Url("file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora"), repo.gpgKeyUrl());
60   }
61
62 }