- rework the testsuite after new boost in factory broke it.
[platform/upstream/libzypp.git] / tests / zypp / RepoManager_test.cc
index a47f3d4..50e96a8 100644 (file)
@@ -9,26 +9,26 @@
 #include "zypp/KeyRing.h"
 #include "zypp/PublicKey.h"
 #include "zypp/TmpPath.h"
-#include "zypp/ResStore.h"
+#include "zypp/PathInfo.h"
 
 #include "zypp/RepoManager.h"
 
 #include <boost/test/unit_test.hpp>
-#include <boost/test/parameterized_test.hpp>
-#include <boost/test/unit_test_log.hpp>
+
 
 #include "KeyRingTestReceiver.h"
 
 using boost::unit_test::test_suite;
 using boost::unit_test::test_case;
-using namespace boost::unit_test::log;
 
 using namespace std;
 using namespace zypp;
 using namespace zypp::filesystem;
 using namespace zypp::repo;
 
-void repomanager_test( const string &dir )
+#define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/RepoManager")
+
+BOOST_AUTO_TEST_CASE(repomanager_test)
 {
   RepoManagerOptions opts;
   
@@ -36,7 +36,7 @@ void repomanager_test( const string &dir )
   TmpDir tmpRawCachePath;
   TmpDir tmpKnownReposPath;
   
-  BOOST_CHECK_EQUAL( filesystem::copy_dir_content( Pathname(dir) + "/repos.d", tmpKnownReposPath.path() ), 0 );
+  BOOST_CHECK_EQUAL( filesystem::copy_dir_content( DATADIR + "/repos.d", tmpKnownReposPath.path() ), 0 );
   
   opts.repoCachePath = tmpCachePath.path();
   opts.repoRawCachePath = tmpRawCachePath.path();
@@ -49,18 +49,22 @@ void repomanager_test( const string &dir )
   
   // now add a .repo file with 2 repositories in it
   Url url;
-  url.setPathName((Pathname(dir) + "/proprietary.repo").asString());
+  url.setPathName((DATADIR + "/proprietary.repo").asString());
   url.setScheme("file");
 
   manager.addRepositories(url);
   
   // check it was not overwriten the proprietary.repo file
-  BOOST_CHECK( PathInfo(Pathname(dir) + "/repos.d/proprietary_1.repo").isExist() );
+  BOOST_CHECK( PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
   
   // now there should be 6 repos
   repos = manager.knownRepositories();
   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6);
   
+  RepoInfo office_dup;
+  office_dup.setAlias("office");
+  BOOST_CHECK_THROW(manager.addRepository(office_dup), RepoAlreadyExistsException);
+
   // delete the office repo inside the propietary_1.repo
   RepoInfo office;
   office.setAlias("office");
@@ -69,7 +73,7 @@ void repomanager_test( const string &dir )
   repos = manager.knownRepositories();
   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 5);
   // the file still contained one repo, so it should still exists
-  BOOST_CHECK( PathInfo(Pathname(dir) + "/repos.d/proprietary_1.repo").isExist() );
+  BOOST_CHECK( PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
   
   // now delete the macromedia one
   RepoInfo macromedia;
@@ -78,27 +82,63 @@ void repomanager_test( const string &dir )
   repos = manager.knownRepositories();
   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
   // the file should not exist anymore
-  BOOST_CHECK( ! PathInfo(Pathname(dir) + "/repos.d/proprietary_1.repo").isExist() );
-  
-  RepoInfo repo(repos.front());
-  manager.refreshMetadata(repo);
-  
-  Repository repository;
-  try {
-    repository = manager.createFromCache(repo);
-  }
-  catch ( const RepoNotCachedException &e )
-  {
-    ZYPP_CAUGHT(e);
-    MIL << "repo " << repo.alias() << " not cached yet. Caching..." << endl;
-    manager.buildCache(repo);
-    repository = manager.createFromCache(repo);
-  }
+  BOOST_CHECK( ! PathInfo(tmpKnownReposPath.path() + "/proprietary.repo_1").isExist() );
   
-  ResStore store = repository.resolvables();
-  MIL << store.size() << " resolvables" << endl;
+
+  // let test cache creation
+
+  RepoInfo repo;
+  repo.setAlias("foo");
+  Url repourl("dir:" + string(TESTS_SRC_DIR) + "/repo/yum/data/10.2-updates-subset");
+  //Url repourl("dir:/mounts/dist/install/stable-x86/suse");
+  //BOOST_CHECK_MESSAGE(0, repourl.asString());
+  repo.setBaseUrl(repourl);
+
+  KeyRingTestReceiver keyring_callbacks;
+  KeyRingTestSignalReceiver receiver;
   
+  // disable sgnature checking
+  keyring_callbacks.answerTrustKey(true);
+  keyring_callbacks.answerAcceptVerFailed(true);
+  keyring_callbacks.answerAcceptUnknownKey(true);
+
+  // we have no metadata yet so this should throw
+  BOOST_CHECK_THROW( manager.buildCache(repo),
+                     RepoMetadataException );
+
+  // now refresh the metadata
   manager.refreshMetadata(repo);
+  
+  BOOST_CHECK_MESSAGE( ! manager.isCached(repo),
+                       "Repo is not yet cached" );
+
+  // it is not cached, this should throw
+  BOOST_CHECK_THROW( manager.loadFromCache(repo),
+                     RepoNotCachedException );
+
+  // now cache should build normally
+  manager.buildCache(repo);
+
+   // the solv file should exists now
+  Pathname base = (opts.repoCachePath + repo.alias());
+  Pathname solvfile = base.extend(".solv");
+  Pathname cookiefile = base.extend(".cookie");
+  BOOST_CHECK_MESSAGE( PathInfo(solvfile).isExist(), "Solv file is created after caching: " + solvfile.asString());
+  BOOST_CHECK_MESSAGE( PathInfo(cookiefile).isExist(), "Cookie file is created after caching: " + cookiefile.asString());
+
+  BOOST_CHECK_MESSAGE( manager.isCached(repo),
+                       "Repo is cached now" );
+
+  MIL << "Repo already in cache, clean cache"<< endl;
+  manager.cleanCache(repo);
+
+  BOOST_CHECK_MESSAGE( !manager.isCached(repo),
+                       "Repo cache was just deleted, should not be cached now" );
+
+  // now cache should build normally
+  manager.buildCache(repo);
+
+  manager.loadFromCache(repo);
 
   if ( manager.isCached(repo ) )
   {
@@ -109,28 +149,3 @@ void repomanager_test( const string &dir )
   manager.buildCache(repo);
 }
 
-test_suite*
-init_unit_test_suite( int argc, char* argv[] )
-{
-  string datadir;
-  if (argc < 2)
-  {
-    datadir = TESTS_SRC_DIR;
-    datadir = (Pathname(datadir) + "/zypp/data/RepoManager").asString();
-    cout << "repomanager_test:"
-      " path to directory with test data required as parameter. Using " << datadir  << endl;
-    //return (test_suite *)0;
-  }
-  else
-  {
-    datadir = argv[1];
-  }
-
-  std::string const params[] = { datadir };
-    //set_log_stream( std::cout );
-  test_suite* test= BOOST_TEST_SUITE( "RepoManagerTest" );
-  test->add(BOOST_PARAM_TEST_CASE( &repomanager_test,
-                              (std::string const*)params, params+1));
-  return test;
-}
-