7 #include "zypp/base/LogTools.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)
34 RepoManagerOptions opts( RepoManagerOptions::makeTestSetup( tmpCachePath ) ) ;
36 filesystem::mkdir( opts.knownReposPath );
37 BOOST_CHECK_EQUAL( filesystem::copy_dir_content( DATADIR + "/repos.d", opts.knownReposPath ), 0 );
39 RepoManager manager(opts);
41 list<RepoInfo> repos = manager.knownRepositories();
42 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
44 // now add a .repo file with 2 repositories in it
46 url.setPathName((DATADIR + "/proprietary.repo").asString());
47 url.setScheme("file");
49 manager.addRepositories(url);
51 // check it was not overwriten the proprietary.repo file
52 BOOST_CHECK( PathInfo(opts.knownReposPath + "/proprietary.repo_1").isExist() );
54 // now there should be 6 repos
55 repos = manager.knownRepositories();
56 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6);
59 office_dup.setAlias("office");
60 BOOST_CHECK_THROW(manager.addRepository(office_dup), RepoAlreadyExistsException);
62 // delete the office repo inside the propietary_1.repo
64 office.setAlias("office");
65 manager.removeRepository(office);
66 // now there should be 5 repos
67 repos = manager.knownRepositories();
68 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 5);
69 // the file still contained one repo, so it should still exists
70 BOOST_CHECK( PathInfo(opts.knownReposPath + "/proprietary.repo_1").isExist() );
72 // now delete the macromedia one
74 macromedia.setAlias("macromedia");
75 manager.removeRepository(macromedia);
76 repos = manager.knownRepositories();
77 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
78 // the file should not exist anymore
79 BOOST_CHECK( ! PathInfo(opts.knownReposPath + "/proprietary.repo_1").isExist() );
82 // let test cache creation
86 Url repourl("dir:" + string(TESTS_SRC_DIR) + "/repo/yum/data/10.2-updates-subset");
87 //Url repourl("dir:/mounts/dist/install/stable-x86/suse");
88 //BOOST_CHECK_MESSAGE(0, repourl.asString());
89 repo.setBaseUrl(repourl);
91 KeyRingTestReceiver keyring_callbacks;
92 KeyRingTestSignalReceiver receiver;
94 // disable sgnature checking
95 keyring_callbacks.answerTrustKey(true);
96 keyring_callbacks.answerAcceptVerFailed(true);
97 keyring_callbacks.answerAcceptUnknownKey(true);
99 // We have no metadata and cache yet
100 BOOST_CHECK_MESSAGE( !manager.isCached(repo), "Repo should not yet be cached" );
102 // This should download metadata and build the cache
103 manager.buildCache(repo);
105 // Now we have metadata and cache
106 BOOST_CHECK_MESSAGE( manager.isCached(repo), "Repo should be cached now" );
108 // Metadata are up to date
109 RepoManager::RefreshCheckStatus ref_stat = manager.checkIfToRefreshMetadata(repo, *repo.baseUrlsBegin());
110 SEC << endl << ref_stat << endl;
111 BOOST_CHECK_MESSAGE( ref_stat== RepoManager::REPO_UP_TO_DATE || ref_stat == RepoManager::REPO_CHECK_DELAYED, "Metadata should be up to date" );
113 // the solv file should exists now
114 Pathname base = (opts.repoCachePath / "solv" / repo.alias());
115 Pathname solvfile = base / "solv";
116 Pathname cookiefile = base / "cookie";
117 BOOST_CHECK_MESSAGE( PathInfo(solvfile).isExist(), "Solv file is created after caching: " + solvfile.asString());
118 BOOST_CHECK_MESSAGE( PathInfo(cookiefile).isExist(), "Cookie file is created after caching: " + cookiefile.asString());
120 MIL << "Repo already in cache, clean cache"<< endl;
121 manager.cleanCache(repo);
123 BOOST_CHECK_MESSAGE( !manager.isCached(repo),
124 "Repo cache was just deleted, should not be cached now" );
126 // now cache should build normally
127 manager.buildCache(repo);
129 manager.loadFromCache(repo);
131 if ( manager.isCached(repo ) )
133 MIL << "Repo already in cache, clean cache"<< endl;
134 manager.cleanCache(repo);
136 MIL << "Parsing repository metadata..." << endl;
137 manager.buildCache(repo);
140 BOOST_AUTO_TEST_CASE(repo_seting_test)
143 repo.setAlias("foo");
144 repo.addBaseUrl(string("http://test.org"));
145 BOOST_CHECK_MESSAGE( repo.keepPackages(), "http scheme is not cached");
146 repo.setBaseUrl(string("ftp://test.org"));
147 BOOST_CHECK_MESSAGE( repo.keepPackages(), "ftp scheme is not cached");
148 repo.setBaseUrl(string("smb://test.org"));
149 BOOST_CHECK_MESSAGE( !repo.keepPackages(), "smb scheme is cached");
150 repo.setBaseUrl(string("file:///test.txt"));
151 BOOST_CHECK_MESSAGE( !repo.keepPackages(), "file scheme is cached");
152 repo.setBaseUrl(string("http://test.org"));
153 BOOST_CHECK_MESSAGE( repo.keepPackages(), "cache is depend on second url.");