]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: add test for config_parse_pass_environ
authorEvgeny Vereshchagin <evvers@ya.ru>
Sat, 7 Nov 2015 18:54:12 +0000 (18:54 +0000)
committerFilipe Brandenburger <filbranden@google.com>
Wed, 11 Nov 2015 15:55:23 +0000 (07:55 -0800)
src/test/test-unit-file.c

index 3648ec9c580887d0ba9644f967ec77d24a5a51a1..a8e5b6feee3cc5fe77576a26794729a0c4373f7f 100644 (file)
@@ -741,6 +741,44 @@ static void test_config_parse_rlimit(void) {
         rl[RLIMIT_RTTIME] = mfree(rl[RLIMIT_RTTIME]);
 }
 
+static void test_config_parse_pass_environ(void) {
+        /* int config_parse_pass_environ(
+                 const char *unit,
+                 const char *filename,
+                 unsigned line,
+                 const char *section,
+                 unsigned section_line,
+                 const char *lvalue,
+                 int ltype,
+                 const char *rvalue,
+                 void *data,
+                 void *userdata) */
+        int r;
+        _cleanup_strv_free_ char **passenv = NULL;
+
+        r = config_parse_pass_environ(NULL, "fake", 1, "section", 1,
+                              "PassEnvironment", 0, "A B",
+                              &passenv, NULL);
+        assert_se(r >= 0);
+        assert_se(strv_length(passenv) == 2);
+        assert_se(streq(passenv[0], "A"));
+        assert_se(streq(passenv[1], "B"));
+
+        r = config_parse_pass_environ(NULL, "fake", 1, "section", 1,
+                              "PassEnvironment", 0, "",
+                              &passenv, NULL);
+        assert_se(r >= 0);
+        assert_se(strv_isempty(passenv));
+
+        r = config_parse_pass_environ(NULL, "fake", 1, "section", 1,
+                              "PassEnvironment", 0, "'invalid name' 'normal_name' A=1 \\",
+                              &passenv, NULL);
+        assert_se(r >= 0);
+        assert_se(strv_length(passenv) == 1);
+        assert_se(streq(passenv[0], "normal_name"));
+
+}
+
 int main(int argc, char *argv[]) {
         int r;
 
@@ -751,6 +789,7 @@ int main(int argc, char *argv[]) {
         test_config_parse_exec();
         test_config_parse_bounding_set();
         test_config_parse_rlimit();
+        test_config_parse_pass_environ();
         test_load_env_file_1();
         test_load_env_file_2();
         test_load_env_file_3();