7 #include "zypp/base/Logger.h"
8 #include "zypp/base/Exception.h"
9 #include "zypp/KeyRing.h"
10 #include "zypp/PublicKey.h"
11 #include "zypp/TmpPath.h"
12 #include "zypp/PathInfo.h"
14 #include "zypp/RepoManager.h"
16 #include <boost/test/auto_unit_test.hpp>
19 #include "KeyRingTestReceiver.h"
21 using boost::unit_test::test_suite;
22 using boost::unit_test::test_case;
26 using namespace zypp::filesystem;
27 using namespace zypp::repo;
29 #define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/RepoManager")
31 BOOST_AUTO_TEST_CASE(repomanager_test)
33 RepoManagerOptions opts;
36 TmpDir tmpRawCachePath;
37 TmpDir tmpKnownReposPath;
39 BOOST_CHECK_EQUAL( filesystem::copy_dir_content( DATADIR + "/repos.d", tmpKnownReposPath.path() ), 0 );
41 opts.repoCachePath = tmpCachePath.path();
42 opts.repoRawCachePath = tmpRawCachePath.path();
43 opts.knownReposPath = tmpKnownReposPath.path();
45 RepoManager manager(opts);
47 list<RepoInfo> repos = manager.knownRepositories();
48 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
50 // now add a .repo file with 2 repositories in it
52 url.setPathName((DATADIR + "/proprietary.repo").asString());
53 url.setScheme("file");
55 manager.addRepositories(url);
57 // check it was not overwriten the proprietary.repo file
58 BOOST_CHECK( PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
60 // now there should be 6 repos
61 repos = manager.knownRepositories();
62 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6);
65 office_dup.setAlias("office");
66 BOOST_CHECK_THROW(manager.addRepository(office_dup), RepoAlreadyExistsException);
68 // delete the office repo inside the propietary_1.repo
70 office.setAlias("office");
71 manager.removeRepository(office);
72 // now there should be 5 repos
73 repos = manager.knownRepositories();
74 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 5);
75 // the file still contained one repo, so it should still exists
76 BOOST_CHECK( PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
78 // now delete the macromedia one
80 macromedia.setAlias("macromedia");
81 manager.removeRepository(macromedia);
82 repos = manager.knownRepositories();
83 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
84 // the file should not exist anymore
85 BOOST_CHECK( ! PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
88 // let test cache creation
92 Url repourl("dir:" + string(TESTS_SRC_DIR) + "/repo/yum/data/10.2-updates-subset");
93 //Url repourl("dir:/mounts/dist/install/stable-x86/suse");
94 //BOOST_CHECK_MESSAGE(0, repourl.asString());
95 repo.setBaseUrl(repourl);
97 KeyRingTestReceiver keyring_callbacks;
98 KeyRingTestSignalReceiver receiver;
100 // disable sgnature checking
101 keyring_callbacks.answerTrustKey(true);
102 keyring_callbacks.answerAcceptVerFailed(true);
103 keyring_callbacks.answerAcceptUnknownKey(true);
105 // we have no metadata yet so this should throw
106 BOOST_CHECK_THROW( manager.buildCache(repo),
107 RepoMetadataException );
109 // now refresh the metadata
110 manager.refreshMetadata(repo);
112 BOOST_CHECK_MESSAGE( ! manager.isCached(repo),
113 "Repo is not yet cached" );
115 // it is not cached, this should throw
116 BOOST_CHECK_THROW( manager.loadFromCache(repo),
117 RepoNotCachedException );
119 // now cache should build normally
120 manager.buildCache(repo);
122 // the solv file should exists now
123 Pathname base = (opts.repoCachePath + repo.alias());
124 Pathname solvfile = base.extend(".solv");
125 Pathname cookiefile = base.extend(".cookie");
126 BOOST_CHECK_MESSAGE( PathInfo(solvfile).isExist(), "Solv file is created after caching: " + solvfile.asString());
127 BOOST_CHECK_MESSAGE( PathInfo(cookiefile).isExist(), "Cookie file is created after caching: " + cookiefile.asString());
129 BOOST_CHECK_MESSAGE( manager.isCached(repo),
130 "Repo is cached now" );
132 MIL << "Repo already in cache, clean cache"<< endl;
133 manager.cleanCache(repo);
135 BOOST_CHECK_MESSAGE( !manager.isCached(repo),
136 "Repo cache was just deleted, should not be cached now" );
138 // now cache should build normally
139 manager.buildCache(repo);
141 manager.loadFromCache(repo);
143 if ( manager.isCached(repo ) )
145 MIL << "Repo already in cache, clean cache"<< endl;
146 manager.cleanCache(repo);
148 MIL << "Parsing repository metadata..." << endl;
149 manager.buildCache(repo);