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/ResStore.h"
13 #include "zypp/PathInfo.h"
15 #include "zypp/RepoManager.h"
17 #include <boost/test/unit_test.hpp>
18 #include <boost/test/parameterized_test.hpp>
19 #include <boost/test/unit_test_log.hpp>
21 #include "KeyRingTestReceiver.h"
23 using boost::unit_test::test_suite;
24 using boost::unit_test::test_case;
25 using namespace boost::unit_test::log;
29 using namespace zypp::filesystem;
30 using namespace zypp::repo;
32 void repomanager_test( const string &dir )
34 RepoManagerOptions opts;
37 TmpDir tmpRawCachePath;
38 TmpDir tmpKnownReposPath;
40 BOOST_CHECK_EQUAL( filesystem::copy_dir_content( Pathname(dir) + "/repos.d", tmpKnownReposPath.path() ), 0 );
42 opts.repoCachePath = tmpCachePath.path();
43 opts.repoRawCachePath = tmpRawCachePath.path();
44 opts.knownReposPath = tmpKnownReposPath.path();
46 RepoManager manager(opts);
48 list<RepoInfo> repos = manager.knownRepositories();
49 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
51 // now add a .repo file with 2 repositories in it
53 url.setPathName((Pathname(dir) + "/proprietary.repo").asString());
54 url.setScheme("file");
56 manager.addRepositories(url);
58 // check it was not overwriten the proprietary.repo file
59 BOOST_CHECK( PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
61 // now there should be 6 repos
62 repos = manager.knownRepositories();
63 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6);
66 office_dup.setAlias("office");
67 BOOST_CHECK_THROW(manager.addRepository(office_dup), RepoAlreadyExistsException);
69 // delete the office repo inside the propietary_1.repo
71 office.setAlias("office");
72 manager.removeRepository(office);
73 // now there should be 5 repos
74 repos = manager.knownRepositories();
75 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 5);
76 // the file still contained one repo, so it should still exists
77 BOOST_CHECK( PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
79 // now delete the macromedia one
81 macromedia.setAlias("macromedia");
82 manager.removeRepository(macromedia);
83 repos = manager.knownRepositories();
84 BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
85 // the file should not exist anymore
86 BOOST_CHECK( ! PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
89 // let test cache creation
93 //Url repourl("dir:" + string(TESTS_SRC_DIR) + "/repo/yum/data/10.2-updates-subset");
94 Url repourl("dir:/mounts/dist/install/stable-x86/suse");
95 //BOOST_CHECK_MESSAGE(0, repourl.asString());
96 repo.setBaseUrl(repourl);
98 KeyRingTestReceiver keyring_callbacks;
99 KeyRingTestSignalReceiver receiver;
101 // disable sgnature checking
102 keyring_callbacks.answerTrustKey(true);
103 keyring_callbacks.answerAcceptVerFailed(true);
104 keyring_callbacks.answerAcceptUnknownKey(true);
106 manager.refreshMetadata(repo);
108 BOOST_CHECK_MESSAGE( ! manager.isCached(repo),
109 "Repo is not yet cached" );
110 manager.buildCache(repo);
112 // we have no metadata yet so this should throw
113 //BOOST_CHECK_THROW( manager.buildCache(repo),
114 // RepoMetadataException );
118 Repository repository;
120 // it is not cached, this should throw
121 BOOST_CHECK_THROW( manager.createFromCache(repo),
122 RepoNotCachedException );
124 MIL << "repo " << repo.alias() << " not cached yet. Caching..." << endl;
125 manager.buildCache(repo);
127 // the solv file should exists now
128 Pathname solvfile = (opts.repoCachePath + repo.alias()).extend(".solv");
129 BOOST_CHECK_MESSAGE( !PathInfo(solvfile).isExist(), "Solv file is created after caching");
131 repository = manager.createFromCache(repo);
133 BOOST_CHECK_MESSAGE( manager.isCached(repo),
136 ResStore store = repository.resolvables();
137 MIL << store.size() << " resolvables" << endl;
139 manager.refreshMetadata(repo);
141 if ( manager.isCached(repo ) )
143 MIL << "Repo already in cache, clean cache"<< endl;
144 manager.cleanCache(repo);
146 MIL << "Parsing repository metadata..." << endl;
147 manager.buildCache(repo);
151 init_unit_test_suite( int argc, char* argv[] )
156 datadir = TESTS_SRC_DIR;
157 datadir = (Pathname(datadir) + "/zypp/data/RepoManager").asString();
158 cout << "repomanager_test:"
159 " path to directory with test data required as parameter. Using " << datadir << endl;
160 //return (test_suite *)0;
167 std::string const params[] = { datadir };
168 //set_log_stream( std::cout );
169 test_suite* test= BOOST_TEST_SUITE( "RepoManagerTest" );
170 test->add(BOOST_PARAM_TEST_CASE( &repomanager_test,
171 (std::string const*)params, params+1));