]> git.ipfire.org Git - people/ms/pakfire.git/blame - tests/libpakfire/jail.c
Makefile: Define TEST_STUB_ROOT in testsuite
[people/ms/pakfire.git] / tests / libpakfire / jail.c
CommitLineData
3334e9c0
MT
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
25static const char* cmd[2] = {
26 "/usr/bin/does-not-exist",
27};
28
29static int test_create(const struct test* t) {
30 struct pakfire_jail* jail = NULL;
31
32 // Create a new jail
d639929b 33 ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, 0));
3334e9c0
MT
34
35 // Destroy it
36 ASSERT_NULL(pakfire_jail_unref(jail));
37
00ba1d9a
MT
38 // Create an interactive jail
39 ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, PAKFIRE_JAIL_INTERACTIVE));
40
41 // Destroy it again
42 ASSERT_NULL(pakfire_jail_unref(jail));
43
3334e9c0
MT
44 return EXIT_SUCCESS;
45
46FAIL:
47 return EXIT_FAILURE;
48}
49
32d5f21d
MT
50static int test_env(const struct test* t) {
51 struct pakfire_jail* jail = NULL;
52
53 // Create a new jail
d639929b 54 ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, 0));
32d5f21d 55
d5bc8fe0
MT
56 // Check if the default variables are set
57 ASSERT(pakfire_jail_get_env(jail, "LANG"));
58 ASSERT(pakfire_jail_get_env(jail, "TERM"));
59
32d5f21d
MT
60 // Fetch a non-existing environment variable
61 ASSERT_NULL(pakfire_jail_get_env(jail, "VARIABLE"));
62
63 // Set a variable
64 ASSERT_SUCCESS(pakfire_jail_set_env(jail, "VARIABLE", "VALUE"));
65
66 // Read the value back
67 ASSERT_STRING_EQUALS(pakfire_jail_get_env(jail, "VARIABLE"), "VALUE");
68
69 // Destroy it
70 ASSERT_NULL(pakfire_jail_unref(jail));
71
72 return EXIT_SUCCESS;
73
74FAIL:
75 return EXIT_FAILURE;
76}
77
78
3334e9c0
MT
79int main(int argc, char** argv) {
80 testsuite_add_test(test_create);
32d5f21d 81 testsuite_add_test(test_env);
3334e9c0
MT
82
83 return testsuite_run();
84}