pacemaker  3.0.0-d8340737c4
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->priv = pcmk__assert_alloc(1, sizeof(struct pcmk__node_private));
31  b->priv = pcmk__assert_alloc(1, sizeof(struct pcmk__node_private));
32 
33  a->priv->name = "cluster1";
34  b->priv->name = "cluster2";
35 
36  nodes = g_list_append(nodes, a);
37  nodes = g_list_append(nodes, b);
38 
39  assert_ptr_equal(a, pcmk__find_node_in_list(nodes, "cluster1"));
40  assert_null(pcmk__find_node_in_list(nodes, "cluster10"));
41  assert_null(pcmk__find_node_in_list(nodes, "nodecluster1"));
42  assert_ptr_equal(b, pcmk__find_node_in_list(nodes, "CLUSTER2"));
43  assert_null(pcmk__find_node_in_list(nodes, "xyz"));
44 
45  free(a->priv);
46  free(a);
47  free(b->priv);
48  free(b);
49  g_list_free(nodes);
50 }
51 
52 PCMK__UNIT_TEST(NULL, NULL,
53  cmocka_unit_test(empty_list),
54  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 * pcmk__find_node_in_list(const GList *nodes, const char *node_name)
Definition: nodes.c:170
#define pcmk__assert_alloc(nmemb, size)
Definition: internal.h:257