Let's make the tests also compile with boost 1.33 (auto_unit_test.hpp is
[platform/upstream/libzypp.git] / tests / zypp / RepoManager_test.cc
1
2 #include <iostream>
3 #include <fstream>
4 #include <list>
5 #include <string>
6
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"
13
14 #include "zypp/RepoManager.h"
15
16 #include <boost/test/auto_unit_test.hpp>
17
18
19 #include "KeyRingTestReceiver.h"
20
21 using boost::unit_test::test_suite;
22 using boost::unit_test::test_case;
23
24 using namespace std;
25 using namespace zypp;
26 using namespace zypp::filesystem;
27 using namespace zypp::repo;
28
29 #define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/RepoManager")
30
31 BOOST_AUTO_TEST_CASE(repomanager_test)
32 {
33   RepoManagerOptions opts;
34   
35   TmpDir tmpCachePath;
36   TmpDir tmpRawCachePath;
37   TmpDir tmpKnownReposPath;
38   
39   BOOST_CHECK_EQUAL( filesystem::copy_dir_content( DATADIR + "/repos.d", tmpKnownReposPath.path() ), 0 );
40   
41   opts.repoCachePath = tmpCachePath.path();
42   opts.repoRawCachePath = tmpRawCachePath.path();
43   opts.knownReposPath = tmpKnownReposPath.path();
44   
45   RepoManager manager(opts);
46   
47   list<RepoInfo> repos = manager.knownRepositories();
48   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
49   
50   // now add a .repo file with 2 repositories in it
51   Url url;
52   url.setPathName((DATADIR + "/proprietary.repo").asString());
53   url.setScheme("file");
54
55   manager.addRepositories(url);
56   
57   // check it was not overwriten the proprietary.repo file
58   BOOST_CHECK( PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
59   
60   // now there should be 6 repos
61   repos = manager.knownRepositories();
62   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6);
63   
64   RepoInfo office_dup;
65   office_dup.setAlias("office");
66   BOOST_CHECK_THROW(manager.addRepository(office_dup), RepoAlreadyExistsException);
67
68   // delete the office repo inside the propietary_1.repo
69   RepoInfo office;
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() );
77   
78   // now delete the macromedia one
79   RepoInfo macromedia;
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() );
86   
87
88   // let test cache creation
89
90   RepoInfo repo;
91   repo.setAlias("foo");
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);
96
97   KeyRingTestReceiver keyring_callbacks;
98   KeyRingTestSignalReceiver receiver;
99   
100   // disable sgnature checking
101   keyring_callbacks.answerTrustKey(true);
102   keyring_callbacks.answerAcceptVerFailed(true);
103   keyring_callbacks.answerAcceptUnknownKey(true);
104
105   // we have no metadata yet so this should throw
106   BOOST_CHECK_THROW( manager.buildCache(repo),
107                      RepoMetadataException );
108
109   // now refresh the metadata
110   manager.refreshMetadata(repo);
111   
112   BOOST_CHECK_MESSAGE( ! manager.isCached(repo),
113                        "Repo is not yet cached" );
114
115   // it is not cached, this should throw
116   BOOST_CHECK_THROW( manager.loadFromCache(repo),
117                      RepoNotCachedException );
118
119   // now cache should build normally
120   manager.buildCache(repo);
121
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());
128
129   BOOST_CHECK_MESSAGE( manager.isCached(repo),
130                        "Repo is cached now" );
131
132   MIL << "Repo already in cache, clean cache"<< endl;
133   manager.cleanCache(repo);
134
135   BOOST_CHECK_MESSAGE( !manager.isCached(repo),
136                        "Repo cache was just deleted, should not be cached now" );
137
138   // now cache should build normally
139   manager.buildCache(repo);
140
141   manager.loadFromCache(repo);
142
143   if ( manager.isCached(repo ) )
144   {
145     MIL << "Repo already in cache, clean cache"<< endl;
146     manager.cleanCache(repo);
147   }
148   MIL << "Parsing repository metadata..." << endl;
149   manager.buildCache(repo);
150 }
151