pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pe_find_node_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022-2023 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 
13 #include <crm/pengine/internal.h>
14 
15 static void
16 empty_list(void **state) {
17  assert_null(pe_find_node(NULL, NULL));
18  assert_null(pe_find_node(NULL, "cluster1"));
19 }
20 
21 static void
22 non_null_list(void **state) {
23  GList *nodes = NULL;
24 
25  pcmk_node_t *a = calloc(1, sizeof(pcmk_node_t));
26  pcmk_node_t *b = calloc(1, sizeof(pcmk_node_t));
27 
28  a->details = calloc(1, sizeof(struct pe_node_shared_s));
29  a->details->uname = "cluster1";
30  b->details = calloc(1, sizeof(struct pe_node_shared_s));
31  b->details->uname = "cluster2";
32 
33  nodes = g_list_append(nodes, a);
34  nodes = g_list_append(nodes, b);
35 
36  assert_ptr_equal(a, pe_find_node(nodes, "cluster1"));
37  assert_null(pe_find_node(nodes, "cluster10"));
38  assert_null(pe_find_node(nodes, "nodecluster1"));
39  assert_ptr_equal(b, pe_find_node(nodes, "CLUSTER2"));
40  assert_null(pe_find_node(nodes, "xyz"));
41 
42  free(a->details);
43  free(a);
44  free(b->details);
45  free(b);
46  g_list_free(nodes);
47 }
48 
49 PCMK__UNIT_TEST(NULL, NULL,
50  cmocka_unit_test(empty_list),
51  cmocka_unit_test(non_null_list))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
pcmk_node_t * pe_find_node(const GList *node_list, const char *node_name)
Find a node by name in a list of nodes.
Definition: status.c:473
struct pe_node_shared_s * details
Basic node information.
Definition: nodes.h:134
const char * uname
Node name in cluster.
Definition: nodes.h:68
Implementation of pcmk_node_t.
Definition: nodes.h:130
Basic node information (all node objects for the same node share this)
Definition: nodes.h:66