- everything now in place with product repo matching
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 21 Nov 2008 15:33:26 +0000 (15:33 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 21 Nov 2008 15:33:26 +0000 (15:33 +0000)
- add testcase
- it is not used right now, but API has to be in place

tests/repo/CMakeLists.txt
tests/repo/ExtendedMetadata_test.cc [new file with mode: 0644]
tests/repo/OutdatedMetadata_test.cc [deleted file]
tests/repo/yum/data/extensions/repodata/repomd.xml
tests/repo/yum/data/extensions/repodata/suseinfo.xml.gz
zypp/Repository.cc
zypp/Repository.h

index 321613a..073a4cb 100644 (file)
@@ -4,4 +4,4 @@ ADD_SUBDIRECTORY( susetags )
 # to find the KeyRingTest receiver
 INCLUDE_DIRECTORIES( ${LIBZYPP_SOURCE_DIR}/tests/zypp )
 
-ADD_TESTS(RepoVariables OutdatedMetadata)
+ADD_TESTS(RepoVariables ExtendedMetadata)
diff --git a/tests/repo/ExtendedMetadata_test.cc b/tests/repo/ExtendedMetadata_test.cc
new file mode 100644 (file)
index 0000000..3cf14e2
--- /dev/null
@@ -0,0 +1,94 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <list>
+#include <string>
+
+#include <boost/test/auto_unit_test.hpp>
+
+#include "zypp/base/Logger.h"
+#include "zypp/base/Exception.h"
+#include "zypp/PathInfo.h"
+#include "zypp/TmpPath.h"
+#include "zypp/RepoManager.h"
+#include "zypp/sat/Pool.h"
+#include "KeyRingTestReceiver.h"
+
+#include "TestSetup.h"
+
+using boost::unit_test::test_case;
+
+using namespace std;
+using namespace zypp;
+using namespace zypp::repo;
+using namespace zypp::filesystem;
+
+#define TEST_DIR TESTS_SRC_DIR "/repo/yum/data/extensions"
+
+BOOST_AUTO_TEST_CASE(extended_metadata)
+{
+  KeyRingTestReceiver rec;
+  //rec.answerAcceptUnknownKey(true);
+  rec.answerAcceptUnsignedFile(true);
+  
+
+//  rec.answerImportKey(true);
+  Pathname repodir(TEST_DIR );
+
+  sat::Pool pool(sat::Pool::instance());
+
+  TestSetup test( Arch_x86_64 );
+  test.loadRepo(Url(string("dir:") + repodir.absolutename().asString()), "updates");
+
+  Repository repo = pool.reposFind("updates");
+  
+  BOOST_CHECK_EQUAL( repo.generatedTimestamp(), Date(1227279057) );
+  BOOST_CHECK_EQUAL( repo.suggestedExpirationTimestamp(), Date(1227279057 + 3600) );  
+
+  // check that the attributes of product compatibility are ok
+  int count = 0;
+  vector<string> cpeids;
+  vector<string> labels;
+
+  for_( it,
+        repo.compatibleWithProductBegin(),
+        repo.compatibleWithProductEnd() )
+  {
+      cpeids.push_back(it.cpeId());
+      labels.push_back(it.label());
+      count++;
+  }
+
+  // there were 2 compatible products
+  BOOST_CHECK_EQUAL( count, 2 );
+  BOOST_CHECK_EQUAL( cpeids[0], "cpe://o:opensuse" );
+  BOOST_CHECK_EQUAL( cpeids[1], "cpe://o:sle" );
+
+  BOOST_CHECK_EQUAL( labels[0], "openSUSE 11.0" );
+  BOOST_CHECK_EQUAL( labels[1], "SLE 11.0" );
+
+  cpeids.clear();
+  labels.clear();
+  count = 0;
+  
+  for_( it,
+        repo.updatesProductBegin(),
+        repo.updatesProductEnd() )
+  {
+      cpeids.push_back(it.cpeId());
+      labels.push_back(it.label());
+      count++;
+  }
+
+  // the repo updates one product
+  BOOST_CHECK_EQUAL( count, 1 );
+  BOOST_CHECK_EQUAL( cpeids[0], "cpe://o:sle" );
+  BOOST_CHECK_EQUAL( labels[0], "SLE 11.0" );
+
+  // because this product updates something, it _is_ an update repo
+  BOOST_CHECK( repo.isUpdateRepo() );
+
+  BOOST_CHECK( repo.providesUpdatesFor("cpe://o:sle") );
+  BOOST_CHECK( ! repo.providesUpdatesFor("cpe://o:windows") );
+
+}
diff --git a/tests/repo/OutdatedMetadata_test.cc b/tests/repo/OutdatedMetadata_test.cc
deleted file mode 100644 (file)
index be4c73e..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <iostream>
-#include <sstream>
-#include <fstream>
-#include <list>
-#include <string>
-
-#include <boost/test/auto_unit_test.hpp>
-
-#include "zypp/base/Logger.h"
-#include "zypp/base/Exception.h"
-#include "zypp/PathInfo.h"
-#include "zypp/TmpPath.h"
-#include "zypp/RepoManager.h"
-#include "zypp/sat/Pool.h"
-#include "KeyRingTestReceiver.h"
-
-#include "TestSetup.h"
-
-using boost::unit_test::test_case;
-
-using namespace std;
-using namespace zypp;
-using namespace zypp::repo;
-using namespace zypp::filesystem;
-
-#define TEST_DIR TESTS_SRC_DIR "/repo/yum/data/extensions"
-
-BOOST_AUTO_TEST_CASE(extensions)
-{
-  KeyRingTestReceiver rec;
-  //rec.answerAcceptUnknownKey(true);
-  rec.answerAcceptUnsignedFile(true);
-  
-
-//  rec.answerImportKey(true);
-  Pathname repodir(TEST_DIR );
-
-  sat::Pool pool(sat::Pool::instance());
-
-  TestSetup test( Arch_x86_64 );
-  test.loadRepo(Url(string("dir:") + repodir.absolutename().asString()), "updates");
-
-  Repository repo = pool.reposFind("updates");
-  
-  BOOST_CHECK_EQUAL( repo.generatedTimestamp(), Date(1222083131) );
-  BOOST_CHECK_EQUAL( repo.suggestedExpirationTimestamp(), Date(1222083131 + 3600) );  
-}
index 5fb27e3..62bd4c9 100644 (file)
     <timestamp>1215823454</timestamp>
     <open-checksum type="sha">c6bd3c6099de74d97ed045163235be10ffa8a85f</open-checksum>
   </data>
+  
+  
   <data type="suseinfo">
     <location href="repodata/suseinfo.xml.gz"/>
-    <checksum type="sha">a9cf8892e8bb47ed09f05f40e42c390a943e61f5</checksum>
-    <timestamp>1222083131</timestamp>
-    <open-checksum type="sha">a3011438085ac55f06c68053201ea3ded17ee85c</open-checksum>
+    <checksum type="sha">e0b9149c1b7f48c952e9b3ea996669d8d0d9e1e8</checksum>
+    <timestamp>1227279057.0</timestamp>
+    <open-checksum type="sha">b17c055bef95bca397faffdf028cfa91dd1b24bc</open-checksum>
   </data>
 </repomd>
index 39b6c4d..d2f1474 100644 (file)
Binary files a/tests/repo/yum/data/extensions/repodata/suseinfo.xml.gz and b/tests/repo/yum/data/extensions/repodata/suseinfo.xml.gz differ
index 9a1278a..96bfea9 100644 (file)
@@ -106,13 +106,24 @@ namespace zypp
     bool Repository::providesUpdatesFor( const std::string &key ) const
     {
       NO_REPOSITORY_RETURN( false );
+
+      for_( it,
+            updatesProductBegin(),
+            updatesProductEnd() )
+      {
+        // FIXME implement real CPE matching here
+        // someday
+        if ( key == it.cpeId() )
+          return true;
+      }
+        
       return false;
     }
 
     bool Repository::isUpdateRepo() const
     {
       NO_REPOSITORY_RETURN( false );
-      return false;
+      return ( updatesProductBegin() != updatesProductEnd() );
     }
 
     bool Repository::solvablesEmpty() const
index 0fbf9e7..1be3f4f 100644 (file)
@@ -125,6 +125,9 @@ namespace zypp
          * The suggested expiration date of this repository
          * already passed
          *
+         * rpm-md repositories can provide this tag using the
+         * expire extension tag:
+         * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
          */
         bool maybeOutdated() const;
 
@@ -132,18 +135,22 @@ namespace zypp
          * if the repository claims to update something then
          * it is an update repository
          *
-         * This is implemented by looking at an "update" keyword
-         * on the repository tags
+         * This is implemented by looking at the repository updates
+         * tag.
+         * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
          */
         bool isUpdateRepo() const;
 
         /**
          * wether the repository claims to update something \ref prod
-         * with key \ref cpename
+         * with key \ref cpeid
          *
-         * See http://cpe.mitre.org/ for more information on CPE
+         * \see zypp::Product::cpeId()
+         *
+         * See http://cpe.mitre.org/ for more information on the
+         * Common Platform Enumearation.
          */
-        bool providesUpdatesFor( const std::string &cpename ) const;
+        bool providesUpdatesFor( const std::string &cpeid ) const;
 
         /** Whether \ref Repository contains solvables. */
         bool solvablesEmpty() const;
@@ -165,6 +172,8 @@ namespace zypp
       /**
        * Get an iterator to the beginning of the repository
        * compatible distros.
+       * \note This is only a hint. There is no guarantee that
+       * the repository is built for that product.
        * \see Repository::ProductInfoIterator
        */
       ProductInfoIterator compatibleWithProductBegin() const;