|
|
8d419f |
From 01df4d485c8a6f3493a83a2a61572e9f2bccb649 Mon Sep 17 00:00:00 2001
|
|
|
8d419f |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
8d419f |
Date: Wed, 19 Jan 2022 09:39:55 +0100
|
|
|
8d419f |
Subject: [PATCH] test-load-fragment: add a basic test for
|
|
|
8d419f |
config_parse_unit_env_file()
|
|
|
8d419f |
|
|
|
8d419f |
(cherry picked from commit 3ef86964ed151aa2464701eef46d665adfd70895)
|
|
|
8d419f |
|
|
|
8d419f |
Related: #2017035
|
|
|
8d419f |
---
|
|
|
8d419f |
src/test/test-load-fragment.c | 64 +++++++++++++++++++++++++++++++++++
|
|
|
8d419f |
1 file changed, 64 insertions(+)
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c
|
|
|
8d419f |
index 1bd68c7e0a..fbe4744333 100644
|
|
|
8d419f |
--- a/src/test/test-load-fragment.c
|
|
|
8d419f |
+++ b/src/test/test-load-fragment.c
|
|
|
8d419f |
@@ -773,6 +773,70 @@ TEST(config_parse_pass_environ) {
|
|
|
8d419f |
assert_se(streq(passenv[0], "normal_name"));
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
+TEST(config_parse_unit_env_file) {
|
|
|
8d419f |
+ /* int config_parse_unit_env_file(
|
|
|
8d419f |
+ const char *unit,
|
|
|
8d419f |
+ const char *filename,
|
|
|
8d419f |
+ unsigned line,
|
|
|
8d419f |
+ const char *section,
|
|
|
8d419f |
+ unsigned section_line,
|
|
|
8d419f |
+ const char *lvalue,
|
|
|
8d419f |
+ int ltype,
|
|
|
8d419f |
+ const char *rvalue,
|
|
|
8d419f |
+ void *data,
|
|
|
8d419f |
+ void *userdata) */
|
|
|
8d419f |
+
|
|
|
8d419f |
+ _cleanup_(manager_freep) Manager *m = NULL;
|
|
|
8d419f |
+ Unit *u;
|
|
|
8d419f |
+ _cleanup_strv_free_ char **files = NULL;
|
|
|
8d419f |
+ int r;
|
|
|
8d419f |
+
|
|
|
8d419f |
+ r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m);
|
|
|
8d419f |
+ if (manager_errno_skip_test(r)) {
|
|
|
8d419f |
+ log_notice_errno(r, "Skipping test: manager_new: %m");
|
|
|
8d419f |
+ return;
|
|
|
8d419f |
+ }
|
|
|
8d419f |
+
|
|
|
8d419f |
+ assert_se(r >= 0);
|
|
|
8d419f |
+ assert_se(manager_startup(m, NULL, NULL, NULL) >= 0);
|
|
|
8d419f |
+
|
|
|
8d419f |
+ assert_se(u = unit_new(m, sizeof(Service)));
|
|
|
8d419f |
+ assert_se(unit_add_name(u, "foobar.service") == 0);
|
|
|
8d419f |
+
|
|
|
8d419f |
+ r = config_parse_unit_env_file(u->id, "fake", 1, "section", 1,
|
|
|
8d419f |
+ "EnvironmentFile", 0, "not-absolute",
|
|
|
8d419f |
+ &files, u);
|
|
|
8d419f |
+ assert_se(r == 0);
|
|
|
8d419f |
+ assert_se(strv_length(files) == 0);
|
|
|
8d419f |
+
|
|
|
8d419f |
+ r = config_parse_unit_env_file(u->id, "fake", 1, "section", 1,
|
|
|
8d419f |
+ "EnvironmentFile", 0, "/absolute1",
|
|
|
8d419f |
+ &files, u);
|
|
|
8d419f |
+ assert_se(r == 0);
|
|
|
8d419f |
+ assert_se(strv_length(files) == 1);
|
|
|
8d419f |
+
|
|
|
8d419f |
+ r = config_parse_unit_env_file(u->id, "fake", 1, "section", 1,
|
|
|
8d419f |
+ "EnvironmentFile", 0, "/absolute2",
|
|
|
8d419f |
+ &files, u);
|
|
|
8d419f |
+ assert_se(r == 0);
|
|
|
8d419f |
+ assert_se(strv_length(files) == 2);
|
|
|
8d419f |
+ assert_se(streq(files[0], "/absolute1"));
|
|
|
8d419f |
+ assert_se(streq(files[1], "/absolute2"));
|
|
|
8d419f |
+
|
|
|
8d419f |
+ r = config_parse_unit_env_file(u->id, "fake", 1, "section", 1,
|
|
|
8d419f |
+ "EnvironmentFile", 0, "",
|
|
|
8d419f |
+ &files, u);
|
|
|
8d419f |
+ assert_se(r == 0);
|
|
|
8d419f |
+ assert_se(strv_isempty(files));
|
|
|
8d419f |
+
|
|
|
8d419f |
+ r = config_parse_unit_env_file(u->id, "fake", 1, "section", 1,
|
|
|
8d419f |
+ "EnvironmentFile", 0, "/path/%n.conf",
|
|
|
8d419f |
+ &files, u);
|
|
|
8d419f |
+ assert_se(r == 0);
|
|
|
8d419f |
+ assert_se(strv_length(files) == 1);
|
|
|
8d419f |
+ assert_se(streq(files[0], "/path/foobar.service.conf"));
|
|
|
8d419f |
+}
|
|
|
8d419f |
+
|
|
|
8d419f |
TEST(unit_dump_config_items) {
|
|
|
8d419f |
unit_dump_config_items(stdout);
|
|
|
8d419f |
}
|