]> git.ipfire.org Git - people/ms/pakfire.git/blob - tests/libpakfire/jail.c
jail: Implement setting environment variables
[people/ms/pakfire.git] / tests / libpakfire / jail.c
1 /*#############################################################################
2 # #
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2022 Pakfire development team #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 #############################################################################*/
20
21 #include <pakfire/jail.h>
22
23 #include "../testsuite.h"
24
25 static const char* cmd[2] = {
26 "/usr/bin/does-not-exist",
27 };
28
29 static int test_create(const struct test* t) {
30 struct pakfire_jail* jail = NULL;
31
32 // Create a new jail
33 ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire));
34
35 // Destroy it
36 ASSERT_NULL(pakfire_jail_unref(jail));
37
38 return EXIT_SUCCESS;
39
40 FAIL:
41 return EXIT_FAILURE;
42 }
43
44 static int test_env(const struct test* t) {
45 struct pakfire_jail* jail = NULL;
46
47 // Create a new jail
48 ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire));
49
50 // Fetch a non-existing environment variable
51 ASSERT_NULL(pakfire_jail_get_env(jail, "VARIABLE"));
52
53 // Set a variable
54 ASSERT_SUCCESS(pakfire_jail_set_env(jail, "VARIABLE", "VALUE"));
55
56 // Read the value back
57 ASSERT_STRING_EQUALS(pakfire_jail_get_env(jail, "VARIABLE"), "VALUE");
58
59 // Destroy it
60 ASSERT_NULL(pakfire_jail_unref(jail));
61
62 return EXIT_SUCCESS;
63
64 FAIL:
65 return EXIT_FAILURE;
66 }
67
68
69 int main(int argc, char** argv) {
70 testsuite_add_test(test_create);
71 testsuite_add_test(test_env);
72
73 return testsuite_run();
74 }