pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
34static void
35null_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 pcmk__xml_free(xml);
44}
45
46static void
47shutdown_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 pcmk__xml_free(xml);
55}
56
57static void
58shutdown_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 pcmk__xml_free(xml);
65}
66
67PCMK__UNIT_TEST(NULL, NULL,
68 cmocka_unit_test(null_args),
69 cmocka_unit_test(shutdown_absent),
70 cmocka_unit_test(shutdown_present))
Scheduler API for nodes.
const char * pcmk_cib_node_shutdown(xmlNode *cib, const char *node)
Get value of a node's shutdown attribute from CIB, if present.
Definition nodes.c:228
#define CIB_XML
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
void pcmk__xml_free(xmlNode *xml)
Definition xml.c:816
xmlNode * pcmk__xml_parse(const char *input)
Definition xml_io.c:167