diff options
author | Thomas Haller <thaller@redhat.com> | 2021-02-15 13:49:19 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-02-15 14:03:20 +0100 |
commit | 67b0defface5d62d97c11dc3f012d21cb4324503 (patch) | |
tree | 436168c82ad77ddd1d02978244fc9b18f230be63 | |
parent | a18155fc239c22b857c135208134457e7525ded3 (diff) |
tests: add "/bin:/sbin" to "$PATH" for unit tests
We call `tc` from iproute2, which commonly is at "/sbin/tc".
That might not be in the "$PATH" of a regular user, and consequently
we fail to run the test.
Work around that by always adding "/bin" and "/sbin" to the $PATH.
(cherry picked from commit f591aa41c6acb9c890e57c822058b5e47b8aeca6)
-rw-r--r-- | shared/nm-utils/nm-test-utils.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 6b41c11ee9..d51f972ed4 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -624,6 +624,23 @@ __nmtst_init(int * argc, g_setenv("G_MESSAGES_DEBUG", "all", TRUE); } + /* "tc" is in /sbin, which might not be in $PATH of a regular user. Unconditionally + * add "/bin" and "/sbin" to $PATH for all tests. */ + { + static char *path_new; + const char * path_old; + + g_assert(!path_new); + + path_old = g_getenv("PATH"); + path_new = g_strjoin("", + path_old ?: "", + (nm_str_is_empty(path_old) ? "" : ":"), + "/bin:/sbin", + NULL); + g_setenv("PATH", path_new, TRUE); + } + /* Delay messages until we setup logging. */ for (i = 0; i < debug_messages->len; i++) __NMTST_LOG(g_message, "%s", g_array_index(debug_messages, const char *, i)); |