pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
pe_find_node_id_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022-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 
13 #include <crm/pengine/internal.h>
14 
15 static void
16 empty_list(void **state) {
17  assert_null(pe_find_node_id(NULL, NULL));
18  assert_null(pe_find_node_id(NULL, "id1"));
19 }
20 
21 static void
22 non_null_list(void **state) {
23  GList *nodes = NULL;
24 
27 
28  a->priv = pcmk__assert_alloc(1, sizeof(struct pcmk__node_private));
29  b->priv = pcmk__assert_alloc(1, sizeof(struct pcmk__node_private));
30 
31  a->priv->id = "id1";
32  b->priv->id = "id2";
33 
34  nodes = g_list_append(nodes, a);
35  nodes = g_list_append(nodes, b);
36 
37  assert_ptr_equal(a, pe_find_node_id(nodes, "id1"));
38  assert_null(pe_find_node_id(nodes, "id10"));
39  assert_null(pe_find_node_id(nodes, "nodeid1"));
40  assert_ptr_equal(b, pe_find_node_id(nodes, "ID2"));
41  assert_null(pe_find_node_id(nodes, "xyz"));
42 
43  free(a->priv);
44  free(a);
45  free(b->priv);
46  free(b);
47  g_list_free(nodes);
48 }
49 
50 PCMK__UNIT_TEST(NULL, NULL,
51  cmocka_unit_test(empty_list),
52  cmocka_unit_test(non_null_list))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
pcmk__node_private_t * priv
Definition: nodes.h:85
pcmk_node_t * pe_find_node_id(const GList *node_list, const char *id)
Find a node by ID in a list of nodes.
Definition: status.c:510
#define pcmk__assert_alloc(nmemb, size)
Definition: internal.h:257