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

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