pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
14
15static void
16empty_list(void **state) {
17 assert_null(pe_find_node_id(NULL, NULL));
18 assert_null(pe_find_node_id(NULL, "id1"));
19}
20
21static void
22non_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
50PCMK__UNIT_TEST(NULL, NULL,
51 cmocka_unit_test(empty_list),
52 cmocka_unit_test(non_null_list))
#define pcmk__assert_alloc(nmemb, size)
Definition internal.h:246
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:248
pcmk__node_private_t * priv
Definition nodes.h:85
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)