Skip to content

Commit c6ee39c

Browse files
evan-goodekontura
authored andcommitted
C API: test shell-style variable expressions
1 parent f829c16 commit c6ee39c

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

data/tests/vars/var1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
value123

data/tests/vars/var2

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
456
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[shell-expansion]
2+
name=${unset:-${var1:+${var2:+$var2}}}
3+
baseurl=https://${unset:-${var1:+${var2:+$var2}}}
4+
enabled=1
5+
gpgcheck=0

tests/libdnf/dnf-self-test.c

+10
Original file line numberDiff line numberDiff line change
@@ -843,15 +843,18 @@ dnf_repo_loader_func(void)
843843
DnfState *state;
844844
gboolean ret;
845845
g_autofree gchar *repos_dir = NULL;
846+
g_autofree gchar *vars_dir = NULL;
846847
g_autoptr(DnfContext) ctx = NULL;
847848
g_autoptr(DnfRepoLoader) repo_loader = NULL;
848849
guint metadata_expire;
849850

850851
/* set up local context */
851852
ctx = dnf_context_new();
852853
repos_dir = dnf_test_get_filename("yum.repos.d");
854+
vars_dir = dnf_test_get_filename("vars");
853855
dnf_context_set_repo_dir(ctx, repos_dir);
854856
dnf_context_set_solv_dir(ctx, "/tmp");
857+
dnf_context_set_vars_dir(ctx, (const gchar *[]){vars_dir, NULL});
855858
ret = dnf_context_setup(ctx, NULL, &error);
856859
g_assert_no_error(error);
857860
g_assert(ret);
@@ -907,6 +910,13 @@ dnf_repo_loader_func(void)
907910
g_assert_error(error, DNF_ERROR, DNF_ERROR_REPO_NOT_AVAILABLE);
908911
g_assert(!ret);
909912
g_clear_error(&error);
913+
914+
/* check that shell-style variable expressions are correctly expanded in repo values */
915+
dnf_state_reset(state);
916+
repo = dnf_repo_loader_get_repo_by_id(repo_loader, "shell-expansion", &error);
917+
g_assert_no_error(error);
918+
g_assert(repo != NULL);
919+
g_assert_cmpstr(dnf_repo_get_description(repo), ==, "456");
910920
}
911921

912922
static void

0 commit comments

Comments
 (0)