pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pe_find_node_any_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_any(NULL, NULL, NULL));
18  assert_null(pe_find_node_any(NULL, NULL, "cluster1"));
19  assert_null(pe_find_node_any(NULL, "id1", NULL));
20  assert_null(pe_find_node_any(NULL, "id1", "cluster1"));
21 }
22 
23 static void
24 non_null_list(void **state) {
25  GList *nodes = NULL;
26 
27  pcmk_node_t *a = calloc(1, sizeof(pcmk_node_t));
28  pcmk_node_t *b = calloc(1, sizeof(pcmk_node_t));
29 
30  a->details = calloc(1, sizeof(struct pe_node_shared_s));
31  a->details->uname = "cluster1";
32  a->details->id = "id1";
33  b->details = calloc(1, sizeof(struct pe_node_shared_s));
34  b->details->uname = "cluster2";
35  b->details->id = "id2";
36 
37  nodes = g_list_append(nodes, a);
38  nodes = g_list_append(nodes, b);
39 
40  assert_ptr_equal(b, pe_find_node_any(nodes, "id2", NULL));
41  assert_ptr_equal(b, pe_find_node_any(nodes, "ID2", NULL));
42 
43  assert_ptr_equal(a, pe_find_node_any(nodes, "xyz", "cluster1"));
44  assert_ptr_equal(a, pe_find_node_any(nodes, NULL, "cluster1"));
45 
46  assert_null(pe_find_node_any(nodes, "id10", NULL));
47  assert_null(pe_find_node_any(nodes, "nodeid1", NULL));
48  assert_null(pe_find_node_any(nodes, NULL, "cluster10"));
49  assert_null(pe_find_node_any(nodes, NULL, "nodecluster1"));
50  assert_null(pe_find_node_any(nodes, "id3", "cluster3"));
51  assert_null(pe_find_node_any(nodes, NULL, NULL));
52 
53  free(a->details);
54  free(a);
55  free(b->details);
56  free(b);
57  g_list_free(nodes);
58 }
59 
60 PCMK__UNIT_TEST(NULL, NULL,
61  cmocka_unit_test(empty_list),
62  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))
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
const char * id
Node ID at the cluster layer.
Definition: nodes.h:67
pcmk_node_t * pe_find_node_any(const GList *node_list, const char *id, const char *node_name)
Find a node by name or ID in a list of nodes.
Definition: status.c:426
Basic node information (all node objects for the same node share this)
Definition: nodes.h:66