dcavalca / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

Blame SOURCES/0019-Fix-unittests-that-relied-on-checksum-being-at-the-e.patch

52b19a
From 0da73ea1304005b796842d96679d6ea31cdeea3c Mon Sep 17 00:00:00 2001
52b19a
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
52b19a
Date: Tue, 1 Mar 2022 12:42:23 +0100
52b19a
Subject: [PATCH] Fix unittests that relied on checksum being at the end of
52b19a
 solvfiles
52b19a
52b19a
---
52b19a
 tests/test_fill_sack_from_repos_in_cache.py | 26 +++++++++++----------
52b19a
 1 file changed, 14 insertions(+), 12 deletions(-)
52b19a
52b19a
diff --git a/tests/test_fill_sack_from_repos_in_cache.py b/tests/test_fill_sack_from_repos_in_cache.py
52b19a
index a8de287c..30d02cfe 100644
52b19a
--- a/tests/test_fill_sack_from_repos_in_cache.py
52b19a
+++ b/tests/test_fill_sack_from_repos_in_cache.py
52b19a
@@ -39,7 +39,7 @@ TEST_REPO_NAME = "test-repo"
52b19a
 
52b19a
 
52b19a
 class FillSackFromReposInCacheTest(unittest.TestCase):
52b19a
-    def _create_cache_for_repo(self, repopath, tmpdir):
52b19a
+    def _create_cache_for_repo(self, repopath, tmpdir, repo_name=TEST_REPO_NAME):
52b19a
         conf = dnf.conf.MainConf()
52b19a
         conf.cachedir = os.path.join(tmpdir, "cache")
52b19a
         conf.installroot = tmpdir
52b19a
@@ -49,7 +49,7 @@ class FillSackFromReposInCacheTest(unittest.TestCase):
52b19a
 
52b19a
         base = dnf.Base(conf=conf)
52b19a
 
52b19a
-        repoconf = dnf.repo.Repo(TEST_REPO_NAME, base.conf)
52b19a
+        repoconf = dnf.repo.Repo(repo_name, base.conf)
52b19a
         repoconf.baseurl = repopath
52b19a
         repoconf.enable()
52b19a
 
52b19a
@@ -194,6 +194,8 @@ class FillSackFromReposInCacheTest(unittest.TestCase):
52b19a
 
52b19a
     def test_exception_with_checksum_mismatch_and_only_repomd(self):
52b19a
         self._setUp_from_repo_path(os.path.join(os.path.abspath(os.path.dirname(__file__)), "repos/rpm"))
52b19a
+        self._create_cache_for_repo(os.path.join(os.path.abspath(os.path.dirname(__file__)), "repos/drpm"),
52b19a
+                                    self.tmpdir, "drpm-repo")
52b19a
 
52b19a
         # Remove xml metadata except repomd
52b19a
         # repomd.xml is not compressed and doesn't end with .gz
52b19a
@@ -201,12 +203,11 @@ class FillSackFromReposInCacheTest(unittest.TestCase):
52b19a
         for f in repodata_without_repomd:
52b19a
             os.remove(f)
52b19a
 
52b19a
-        # Modify checksum of solv file so it doesn't match with repomd
52b19a
-        solv = glob.glob(os.path.join(self.tmpdir, "cache/*.solv"))[0]
52b19a
-        with open(solv, "a") as opensolv:
52b19a
-            opensolv.write("appended text to change checksum")
52b19a
+        # Replace solvfile of test-repo with solvfile from drpm-repo which has different data (different checksum)
52b19a
+        shutil.move(os.path.join(self.tmpdir, "cache/drpm-repo.solv"),
52b19a
+                    os.path.join(self.tmpdir, "cache/test-repo.solv"))
52b19a
 
52b19a
-        # Now we only have cache with solvx, modified solv file and just repomd
52b19a
+        # Now we only have cache with solvx, mismatching solv file and just repomd
52b19a
         # Since we don't have original xml metadata we cannot regenerate solv -> fail (exception)
52b19a
 
52b19a
         self.assertRaises(dnf.exceptions.RepoError,
52b19a
@@ -214,13 +215,14 @@ class FillSackFromReposInCacheTest(unittest.TestCase):
52b19a
 
52b19a
     def test_checksum_mistmatch_regenerates_solv(self):
52b19a
         self._setUp_from_repo_path(os.path.join(os.path.abspath(os.path.dirname(__file__)), "repos/rpm"))
52b19a
+        self._create_cache_for_repo(os.path.join(os.path.abspath(os.path.dirname(__file__)), "repos/drpm"),
52b19a
+                                    self.tmpdir, "drpm-repo")
52b19a
 
52b19a
-        # Modify checksum of solv file so it doesn't match with repomd
52b19a
-        solv = glob.glob(os.path.join(self.tmpdir, "cache/*.solv"))[0]
52b19a
-        with open(solv, "a") as opensolv:
52b19a
-            opensolv.write("appended text to change checksum")
52b19a
+        # Replace solvfile of test-repo with solvfile from drpm-repo which has different data (different checksum)
52b19a
+        shutil.move(os.path.join(self.tmpdir, "cache/drpm-repo.solv"),
52b19a
+                    os.path.join(self.tmpdir, "cache/test-repo.solv"))
52b19a
 
52b19a
-        # Now we only have cache with solvx, modified solv file and xml metadata.
52b19a
+        # Now we only have cache with solvx, mismatching solv file and xml metadata.
52b19a
         # Checksum mistmatch causes regeneration of solv file and repo works.
52b19a
 
52b19a
         self.test_base.fill_sack_from_repos_in_cache(load_system_repo=False)
52b19a
-- 
52b19a
2.35.1
52b19a