This source file includes following definitions.
- disabled_null_value
- enabled_true_value
- disabled_false_value
- enabled_daemon_in_list
- disabled_daemon_not_in_list
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11 #include <crm/common/unittest_internal.h>
12
13 #include "mock_private.h"
14
15 static void
16 disabled_null_value(void **state)
17 {
18
19 assert_false(pcmk__env_option_enabled(NULL, NULL));
20 assert_false(pcmk__env_option_enabled("pacemaker-execd", NULL));
21 }
22
23 static void
24 enabled_true_value(void **state)
25 {
26
27 pcmk__mock_getenv = true;
28
29 expect_string(__wrap_getenv, name, "PCMK_env_var");
30 will_return(__wrap_getenv, "true");
31 assert_true(pcmk__env_option_enabled(NULL, "env_var"));
32
33 expect_string(__wrap_getenv, name, "PCMK_env_var");
34 will_return(__wrap_getenv, "true");
35 assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var"));
36
37 pcmk__mock_getenv = false;
38 }
39
40 static void
41 disabled_false_value(void **state)
42 {
43
44 pcmk__mock_getenv = true;
45
46 expect_string(__wrap_getenv, name, "PCMK_env_var");
47 will_return(__wrap_getenv, "false");
48 assert_false(pcmk__env_option_enabled(NULL, "env_var"));
49
50 expect_string(__wrap_getenv, name, "PCMK_env_var");
51 will_return(__wrap_getenv, "false");
52 assert_false(pcmk__env_option_enabled("pacemaker-execd", "env_var"));
53
54 pcmk__mock_getenv = false;
55 }
56
57 static void
58 enabled_daemon_in_list(void **state)
59 {
60
61 pcmk__mock_getenv = true;
62
63 expect_string(__wrap_getenv, name, "PCMK_env_var");
64 will_return(__wrap_getenv, "pacemaker-execd");
65 assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var"));
66
67 expect_string(__wrap_getenv, name, "PCMK_env_var");
68 will_return(__wrap_getenv, "pacemaker-execd,pacemaker-fenced");
69 assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var"));
70
71 expect_string(__wrap_getenv, name, "PCMK_env_var");
72 will_return(__wrap_getenv, "pacemaker-controld,pacemaker-execd");
73 assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var"));
74
75 expect_string(__wrap_getenv, name, "PCMK_env_var");
76 will_return(__wrap_getenv,
77 "pacemaker-controld,pacemaker-execd,pacemaker-fenced");
78 assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var"));
79
80 pcmk__mock_getenv = false;
81 }
82
83 static void
84 disabled_daemon_not_in_list(void **state)
85 {
86
87 pcmk__mock_getenv = true;
88
89 expect_string(__wrap_getenv, name, "PCMK_env_var");
90 will_return(__wrap_getenv, "pacemaker-controld,pacemaker-fenced");
91 assert_false(pcmk__env_option_enabled("pacemaker-execd", "env_var"));
92
93 pcmk__mock_getenv = false;
94 }
95
96 PCMK__UNIT_TEST(NULL, NULL,
97 cmocka_unit_test(disabled_null_value),
98 cmocka_unit_test(enabled_true_value),
99 cmocka_unit_test(disabled_false_value),
100 cmocka_unit_test(enabled_daemon_in_list),
101 cmocka_unit_test(disabled_daemon_not_in_list))