pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__find_node_in_list_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 {
18  assert_null(pcmk__find_node_in_list(NULL, NULL));
19  assert_null(pcmk__find_node_in_list(NULL, "cluster1"));
20 }
21 
22 static void
23 non_null_list(void **state)
24 {
25  GList *nodes = NULL;
26 
29 
30  a->details = pcmk__assert_alloc(1, sizeof(struct pe_node_shared_s));
31  a->details->uname = "cluster1";
32  b->details = pcmk__assert_alloc(1, sizeof(struct pe_node_shared_s));
33  b->details->uname = "cluster2";
34 
35  nodes = g_list_append(nodes, a);
36  nodes = g_list_append(nodes, b);
37 
38  assert_ptr_equal(a, pcmk__find_node_in_list(nodes, "cluster1"));
39  assert_null(pcmk__find_node_in_list(nodes, "cluster10"));
40  assert_null(pcmk__find_node_in_list(nodes, "nodecluster1"));
41  assert_ptr_equal(b, pcmk__find_node_in_list(nodes, "CLUSTER2"));
42  assert_null(pcmk__find_node_in_list(nodes, "xyz"));
43 
44  free(a->details);
45  free(a);
46  free(b->details);
47  free(b);
48  g_list_free(nodes);
49 }
50 
51 PCMK__UNIT_TEST(NULL, NULL,
52  cmocka_unit_test(empty_list),
53  cmocka_unit_test(non_null_list))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
pcmk_node_t * pcmk__find_node_in_list(const GList *nodes, const char *node_name)
Definition: nodes.c:150
struct pe_node_shared_s * details
Definition: nodes.h:168
const char * uname
Definition: nodes.h:74
#define pcmk__assert_alloc(nmemb, size)
Definition: internal.h:297