root/lib/common/tests/options/pcmk__env_option_enabled_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. disabled_null_value
  2. enabled_true_value
  3. disabled_false_value
  4. enabled_daemon_in_list
  5. disabled_daemon_not_in_list

   1 /*
   2  * Copyright 2022 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   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)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18     // Return false if option value not found (NULL accomplishes this)
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26     // Return true if option value is true, with or without daemon name
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43     // Return false if option value is false (no daemon list)
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60     // Return true if daemon is in the option's value
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86     // Return false if value is not true and daemon is not in the option's value
  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))

/* [previous][next][first][last][top][bottom][index][help] */