pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk_cib_node_shutdown_test.c
Go to the documentation of this file.
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>
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)
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)
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)
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))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
#define CIB_XML
const char * pcmk_cib_node_shutdown(xmlNode *cib, const char *node)
Get value of a node&#39;s shutdown attribute from CIB, if present.
Definition: nodes.c:181
void free_xml(xmlNode *child)
Definition: xml.c:958
xmlNode * pcmk__xml_parse(const char *input)
Definition: xml_io.c:245
Scheduler API for nodes.