]> git.ipfire.org Git - pakfire.git/commitdiff
tests: execute: Add test to return environment variables
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Jul 2022 08:30:47 +0000 (08:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Jul 2022 08:30:47 +0000 (08:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/python/execute.py
tests/stub/command.c

index cd9eff11a93c9bdd71432f62f6e6a4e31b2bcae0..6cb10e9eb1a0bc4a0407b752718aad303c121da3 100755 (executable)
@@ -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)
index 512d0fd8ff55c1531377e4d7342330f635029e68..9b4990467de37b3b6bc0ae7ca5abd715cc082453 100644 (file)
@@ -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;