Blob Blame History Raw
From 074ca4cf643c79b8ec3db89a7fd5580ba387eb4d Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Wed, 20 Apr 2022 08:22:30 +0200
Subject: [PATCH 27/34] Use environment variable in unittest instead of ugly
 hack in libdnf

Libdnf contains hacks for unit tests. This removes one hack.
---
 libdnf/dnf-repo.cpp          | 3 ---
 tests/libdnf/dnf-self-test.c | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
index 9d42e3e3..c015d7fd 100644
--- a/libdnf/dnf-repo.cpp
+++ b/libdnf/dnf-repo.cpp
@@ -1191,7 +1191,6 @@ dnf_repo_setup(DnfRepo *repo, GError **error) try
     DnfRepoEnabled enabled = DNF_REPO_ENABLED_NONE;
     g_autofree gchar *basearch = NULL;
     g_autofree gchar *release = NULL;
-    g_autofree gchar *testdatadir = NULL;
 
     basearch = g_key_file_get_string(priv->keyfile, "general", "arch", NULL);
     if (basearch == NULL)
@@ -1230,8 +1229,6 @@ dnf_repo_setup(DnfRepo *repo, GError **error) try
     for (const auto & item : libdnf::dnf_context_get_vars(priv->context))
         priv->urlvars = lr_urlvars_set(priv->urlvars, item.first.c_str(), item.second.c_str());
 
-    testdatadir = dnf_realpath(TESTDATADIR);
-    priv->urlvars = lr_urlvars_set(priv->urlvars, "testdatadir", testdatadir);
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_VARSUB, priv->urlvars))
         return FALSE;
     if (!lr_handle_setopt(priv->repo_handle, error, LRO_GNUPGHOMEDIR, priv->keyring))
diff --git a/tests/libdnf/dnf-self-test.c b/tests/libdnf/dnf-self-test.c
index 52958371..906f0e21 100644
--- a/tests/libdnf/dnf-self-test.c
+++ b/tests/libdnf/dnf-self-test.c
@@ -1225,6 +1225,9 @@ main(int argc, char **argv)
     g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
     g_log_set_always_fatal (G_LOG_FATAL_MASK);
 
+    /* Sets a variable to replace in repository configurations. */
+    g_setenv("DNF_VAR_testdatadir", TESTDATADIR, TRUE);
+
     /* tests go here */
     g_test_add_func("/libdnf/repo_loader{gpg-asc}", dnf_repo_loader_gpg_asc_func);
     g_test_add_func("/libdnf/repo_loader{gpg-wrong-asc}", dnf_repo_loader_gpg_wrong_asc_func);
-- 
2.31.1