root/lib/pengine/tests/status/pe_find_node_any_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. empty_list
  2. non_null_list

   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 
  12 #include <crm/common/unittest_internal.h>
  13 #include <crm/pengine/internal.h>
  14 
  15 static void
  16 empty_list(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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 
  23 static void
  24 non_null_list(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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 
  60 PCMK__UNIT_TEST(NULL, NULL,
  61                 cmocka_unit_test(empty_list),
  62                 cmocka_unit_test(non_null_list))

/* [previous][next][first][last][top][bottom][index][help] */