From 40e762da5cd2d876b6424f4c25b77e8dc2422a0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Date: Mon, 8 Feb 2021 08:25:46 +0100
Subject: [PATCH] Set persistdir and substitutions for
fill_sack_from_repos_in_cache tests (RhBug:1865803)
Setting just installroot is not enough because persistdir is not
automatically prepended with installroot if set via API.
Also assert exact package names which is more useful output in case the
test fails.
https://bugzilla.redhat.com/show_bug.cgi?id=1865803
---
tests/test_fill_sack_from_repos_in_cache.py | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/tests/test_fill_sack_from_repos_in_cache.py b/tests/test_fill_sack_from_repos_in_cache.py
index f27235bf84..23fd2a4337 100644
--- a/tests/test_fill_sack_from_repos_in_cache.py
+++ b/tests/test_fill_sack_from_repos_in_cache.py
@@ -42,7 +42,10 @@ class FillSackFromReposInCacheTest(unittest.TestCase):
def _create_cache_for_repo(self, repopath, tmpdir):
conf = dnf.conf.MainConf()
conf.cachedir = os.path.join(tmpdir, "cache")
- conf.installroot = os.path.join(tmpdir)
+ conf.installroot = tmpdir
+ conf.persistdir = os.path.join(conf.installroot, conf.persistdir.lstrip("/"))
+ conf.substitutions["arch"] = "x86_64"
+ conf.substitutions["basearch"] = dnf.rpm.basearch(conf.substitutions["arch"])
base = dnf.Base(conf=conf)
@@ -69,7 +72,10 @@ def _setUp_from_repo_path(self, original_repo_path):
# Prepare base for the actual test
conf = dnf.conf.MainConf()
conf.cachedir = os.path.join(self.tmpdir, "cache")
- conf.installroot = os.path.join(self.tmpdir)
+ conf.installroot = self.tmpdir
+ conf.persistdir = os.path.join(conf.installroot, conf.persistdir.lstrip("/"))
+ conf.substitutions["arch"] = "x86_64"
+ conf.substitutions["basearch"] = dnf.rpm.basearch(conf.substitutions["arch"])
self.test_base = dnf.Base(conf=conf)
repoconf = dnf.repo.Repo(TEST_REPO_NAME, conf)
repoconf.baseurl = self.repo_copy_path
@@ -231,8 +237,13 @@ def test_with_modules_yaml(self):
q = self.test_base.sack.query()
packages = q.run()
- self.assertEqual(len(packages), 8)
- self.assertEqual(packages[0].evr, "2.02-0.40")
+
+ pkg_names = []
+ for pkg in packages:
+ pkg_names.append(pkg.name)
+
+ self.assertEqual(pkg_names, ['grub2', 'httpd', 'httpd', 'httpd-doc', 'httpd-doc', 'httpd-provides-name-doc',
+ 'httpd-provides-name-version-release-doc', 'libnghttp2'])
self.module_base = dnf.module.module_base.ModuleBase(self.test_base)
modules, _ = self.module_base._get_modules("base-runtime*")