pacemaker 2.1.5-a3f44794f94
Scalable High-Availability cluster resource manager
pe_find_node_any_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_any(NULL, NULL, NULL));
18 assert_null(pe_find_node_any(NULL, NULL, "cluster1"));
19 assert_null(pe_find_node_any(NULL, "id1", NULL));
20 assert_null(pe_find_node_any(NULL, "id1", "cluster1"));
21}
22
23static void
24non_null_list(void **state) {
25 GList *nodes = NULL;
26
27 pe_node_t *a = calloc(1, sizeof(pe_node_t));
28 pe_node_t *b = calloc(1, sizeof(pe_node_t));
29
30 a->details = calloc(1, sizeof(struct pe_node_shared_s));
31 a->details->uname = "cluster1";
32 a->details->id = "id1";
33 b->details = calloc(1, sizeof(struct pe_node_shared_s));
34 b->details->uname = "cluster2";
35 b->details->id = "id2";
36
37 nodes = g_list_append(nodes, a);
38 nodes = g_list_append(nodes, b);
39
40 assert_ptr_equal(b, pe_find_node_any(nodes, "id2", NULL));
41 assert_ptr_equal(b, pe_find_node_any(nodes, "ID2", NULL));
42
43 assert_ptr_equal(a, pe_find_node_any(nodes, "xyz", "cluster1"));
44 assert_ptr_equal(a, pe_find_node_any(nodes, NULL, "cluster1"));
45
46 assert_null(pe_find_node_any(nodes, "id10", NULL));
47 assert_null(pe_find_node_any(nodes, "nodeid1", NULL));
48 assert_null(pe_find_node_any(nodes, NULL, "cluster10"));
49 assert_null(pe_find_node_any(nodes, NULL, "nodecluster1"));
50 assert_null(pe_find_node_any(nodes, "id3", "cluster3"));
51 assert_null(pe_find_node_any(nodes, NULL, NULL));
52
53 free(a->details);
54 free(a);
55 free(b->details);
56 free(b);
57 g_list_free(nodes);
58}
59
60PCMK__UNIT_TEST(NULL, NULL,
61 cmocka_unit_test(empty_list),
62 cmocka_unit_test(non_null_list))
pe_node_t * pe_find_node_any(GList *node_list, const char *id, const char *uname)
Definition: status.c:415
struct pe_node_shared_s * details
Definition: pe_types.h:252
const char * id
Definition: pe_types.h:215
const char * uname
Definition: pe_types.h:216
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)