From: Michael Tremer Date: Thu, 21 Jul 2022 08:30:47 +0000 (+0000) Subject: tests: execute: Add test to return environment variables X-Git-Tag: 0.9.28~660 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4316ba87f82e3c3b4b96f1cfa6258049aa6987f8;p=pakfire.git tests: execute: Add test to return environment variables Signed-off-by: Michael Tremer --- diff --git a/tests/python/execute.py b/tests/python/execute.py index cd9eff11a..6cb10e9eb 100755 --- a/tests/python/execute.py +++ b/tests/python/execute.py @@ -30,7 +30,7 @@ class Test(unittest.TestCase): self.assertTrue(code == 123) def test_environ(self): - r = self.pakfire.execute(["/bin/sh", "-c", "echo ${VAR1}"], + r = self.pakfire.execute(["/command", "echo-environ", "VAR1"], environ={"VAR1" : "VAL1"}) self.assertIsNone(r) diff --git a/tests/stub/command.c b/tests/stub/command.c index 512d0fd8f..9b4990467 100644 --- a/tests/stub/command.c +++ b/tests/stub/command.c @@ -30,6 +30,20 @@ static int echo(int argc, char* argv[]) { return 0; } +static int echo_environ(int argc, char* argv[]) { + for (int i = 0; i < argc; i++) { + const char* value = secure_getenv(argv[i]); + if (!value) { + fprintf(stderr, "Variable %s is not set\n", argv[i]); + return 1; + } + + printf("%s\n", value); + } + + return 0; +} + static int exit_with_code(int argc, char* argv[]) { if (argc < 1) { fprintf(stderr, "exit-with-code requires an argument\n"); @@ -53,6 +67,10 @@ int main(int argc, char* argv[]) { if (strcmp(command, "echo") == 0) callback = echo; + // Echo Environment + else if (strcmp(command, "echo-environ") == 0) + callback = echo_environ; + // Exit with code else if (strcmp(command, "exit-with-code") == 0) callback = exit_with_code;