root/lib/common/tests/nodes/pcmk_cib_node_shutdown_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. null_args
  2. shutdown_absent
  3. shutdown_present

   1 /*
   2  * Copyright 2024 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 General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <stdio.h>          // NULL
  13 #include <libxml/tree.h>    // xmlNode
  14 
  15 #include <crm/common/nodes.h>
  16 #include <crm/common/unittest_internal.h>
  17 
  18 // Minimum CIB structure needed for function's XPath search
  19 #define CIB_XML                                                     \
  20     "<" PCMK_XE_CIB ">"                                             \
  21       "<" PCMK_XE_STATUS ">"                                        \
  22         "<" PCMK__XE_NODE_STATE " " PCMK_XA_UNAME "='node1'>"       \
  23           "<" PCMK__XE_TRANSIENT_ATTRIBUTES ">"                     \
  24             "<" PCMK_XE_INSTANCE_ATTRIBUTES ">"                     \
  25               "<" PCMK_XE_NVPAIR " "                                \
  26                   PCMK_XA_NAME "='" PCMK__NODE_ATTR_SHUTDOWN "' "   \
  27                   PCMK_XA_VALUE "='999'/>"                          \
  28             "</" PCMK_XE_INSTANCE_ATTRIBUTES ">"                    \
  29           "</" PCMK__XE_TRANSIENT_ATTRIBUTES ">"                    \
  30         "</" PCMK__XE_NODE_STATE ">"                                \
  31       "</" PCMK_XE_STATUS ">"                                       \
  32     "</" PCMK_XE_CIB ">"
  33 
  34 static void
  35 null_args(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  36 {
  37     xmlNode *xml = pcmk__xml_parse(CIB_XML);
  38 
  39     assert_non_null(xml);
  40     assert_null(pcmk_cib_node_shutdown(NULL, NULL));
  41     assert_null(pcmk_cib_node_shutdown(xml, NULL));
  42     assert_null(pcmk_cib_node_shutdown(NULL, "node1"));
  43     free_xml(xml);
  44 }
  45 
  46 static void
  47 shutdown_absent(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49     xmlNode *xml = pcmk__xml_parse(CIB_XML);
  50 
  51     assert_non_null(xml);
  52     assert_null(pcmk_cib_node_shutdown(xml, "node"));
  53     assert_null(pcmk_cib_node_shutdown(xml, "node10"));
  54     free_xml(xml);
  55 }
  56 
  57 static void
  58 shutdown_present(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60     xmlNode *xml = pcmk__xml_parse(CIB_XML);
  61 
  62     assert_non_null(xml);
  63     assert_string_equal(pcmk_cib_node_shutdown(xml, "node1"), "999");
  64     free_xml(xml);
  65 }
  66 
  67 PCMK__UNIT_TEST(NULL, NULL,
  68                 cmocka_unit_test(null_args),
  69                 cmocka_unit_test(shutdown_absent),
  70                 cmocka_unit_test(shutdown_present))

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