pacemaker 2.1.5-a3f44794f94
Scalable High-Availability cluster resource manager
pe_find_node_id_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2022 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 Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) 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
25 pe_node_t *a = calloc(1, sizeof(pe_node_t));
26 pe_node_t *b = calloc(1, sizeof(pe_node_t));
27
28 a->details = calloc(1, sizeof(struct pe_node_shared_s));
29 a->details->id = "id1";
30 b->details = calloc(1, sizeof(struct pe_node_shared_s));
31 b->details->id = "id2";
32
33 nodes = g_list_append(nodes, a);
34 nodes = g_list_append(nodes, b);
35
36 assert_ptr_equal(a, pe_find_node_id(nodes, "id1"));
37 assert_null(pe_find_node_id(nodes, "id10"));
38 assert_null(pe_find_node_id(nodes, "nodeid1"));
39 assert_ptr_equal(b, pe_find_node_id(nodes, "ID2"));
40 assert_null(pe_find_node_id(nodes, "xyz"));
41
42 free(a->details);
43 free(a);
44 free(b->details);
45 free(b);
46 g_list_free(nodes);
47}
48
49PCMK__UNIT_TEST(NULL, NULL,
50 cmocka_unit_test(empty_list),
51 cmocka_unit_test(non_null_list))
pe_node_t * pe_find_node_id(GList *node_list, const char *id)
Definition: status.c:427
struct pe_node_shared_s * details
Definition: pe_types.h:252
const char * id
Definition: pe_types.h:215
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)