root/lib/pengine/tests/native/pe_base_name_eq_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. bad_args
  4. primitive_rsc
  5. group_rsc
  6. clone_rsc
  7. bundle_rsc

   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 General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/common/unittest_internal.h>
  13 
  14 #include <crm/common/xml.h>
  15 #include <crm/pengine/internal.h>
  16 #include <crm/pengine/status.h>
  17 #include <crm/pengine/pe_types.h>
  18 
  19 xmlNode *input = NULL;
  20 pe_working_set_t *data_set = NULL;
  21 
  22 pe_resource_t *exim_group, *promotable_0, *promotable_1, *dummy;
  23 pe_resource_t *httpd_bundle, *mysql_group_0, *mysql_group_1;
  24 
  25 static int
  26 setup(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  27     char *path = NULL;
  28 
  29     crm_xml_init();
  30 
  31     path = crm_strdup_printf("%s/crm_mon.xml", getenv("PCMK_CTS_CLI_DIR"));
  32     input = filename2xml(path);
  33     free(path);
  34 
  35     if (input == NULL) {
  36         return 1;
  37     }
  38 
  39     data_set = pe_new_working_set();
  40 
  41     if (data_set == NULL) {
  42         return 1;
  43     }
  44 
  45     pe__set_working_set_flags(data_set, pe_flag_no_counts|pe_flag_no_compat);
  46     data_set->input = input;
  47 
  48     cluster_status(data_set);
  49 
  50     /* Get references to several resources we use frequently. */
  51     for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) {
  52         pe_resource_t *rsc = (pe_resource_t *) iter->data;
  53 
  54         if (strcmp(rsc->id, "dummy") == 0) {
  55             dummy = rsc;
  56         } else if (strcmp(rsc->id, "exim-group") == 0) {
  57             exim_group = rsc;
  58         } else if (strcmp(rsc->id, "httpd-bundle") == 0) {
  59             httpd_bundle = rsc;
  60         } else if (strcmp(rsc->id, "mysql-clone-group") == 0) {
  61             for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
  62                 pe_resource_t *child = (pe_resource_t *) iter->data;
  63 
  64                 if (strcmp(child->id, "mysql-group:0") == 0) {
  65                     mysql_group_0 = child;
  66                 } else if (strcmp(child->id, "mysql-group:1") == 0) {
  67                     mysql_group_1 = child;
  68                 }
  69             }
  70         } else if (strcmp(rsc->id, "promotable-clone") == 0) {
  71             for (GList *iter = rsc->children; iter != NULL; iter = iter->next) {
  72                 pe_resource_t *child = (pe_resource_t *) iter->data;
  73 
  74                 if (strcmp(child->id, "promotable-rsc:0") == 0) {
  75                     promotable_0 = child;
  76                 } else if (strcmp(child->id, "promotable-rsc:1") == 0) {
  77                     promotable_1 = child;
  78                 }
  79             }
  80         }
  81     }
  82 
  83     return 0;
  84 }
  85 
  86 static int
  87 teardown(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  88     pe_free_working_set(data_set);
  89 
  90     return 0;
  91 }
  92 
  93 static void
  94 bad_args(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  95     char *id = dummy->id;
  96 
  97     assert_false(pe_base_name_eq(NULL, "dummy"));
  98     assert_false(pe_base_name_eq(dummy, NULL));
  99 
 100     dummy->id = NULL;
 101     assert_false(pe_base_name_eq(dummy, "dummy"));
 102     dummy->id = id;
 103 }
 104 
 105 static void
 106 primitive_rsc(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 107     assert_true(pe_base_name_eq(dummy, "dummy"));
 108     assert_false(pe_base_name_eq(dummy, "DUMMY"));
 109     assert_false(pe_base_name_eq(dummy, "dUmMy"));
 110     assert_false(pe_base_name_eq(dummy, "dummy0"));
 111     assert_false(pe_base_name_eq(dummy, "dummy:0"));
 112 }
 113 
 114 static void
 115 group_rsc(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 116     assert_true(pe_base_name_eq(exim_group, "exim-group"));
 117     assert_false(pe_base_name_eq(exim_group, "EXIM-GROUP"));
 118     assert_false(pe_base_name_eq(exim_group, "exim-group0"));
 119     assert_false(pe_base_name_eq(exim_group, "exim-group:0"));
 120     assert_false(pe_base_name_eq(exim_group, "Public-IP"));
 121 }
 122 
 123 static void
 124 clone_rsc(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 125     assert_true(pe_base_name_eq(promotable_0, "promotable-rsc"));
 126     assert_true(pe_base_name_eq(promotable_1, "promotable-rsc"));
 127 
 128     assert_false(pe_base_name_eq(promotable_0, "promotable-rsc:0"));
 129     assert_false(pe_base_name_eq(promotable_1, "promotable-rsc:1"));
 130     assert_false(pe_base_name_eq(promotable_0, "PROMOTABLE-RSC"));
 131     assert_false(pe_base_name_eq(promotable_1, "PROMOTABLE-RSC"));
 132     assert_false(pe_base_name_eq(promotable_0, "Promotable-rsc"));
 133     assert_false(pe_base_name_eq(promotable_1, "Promotable-rsc"));
 134 }
 135 
 136 static void
 137 bundle_rsc(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 138     assert_true(pe_base_name_eq(httpd_bundle, "httpd-bundle"));
 139     assert_false(pe_base_name_eq(httpd_bundle, "HTTPD-BUNDLE"));
 140     assert_false(pe_base_name_eq(httpd_bundle, "httpd"));
 141     assert_false(pe_base_name_eq(httpd_bundle, "httpd-docker-0"));
 142 }
 143 
 144 PCMK__UNIT_TEST(setup, teardown,
 145                 cmocka_unit_test(bad_args),
 146                 cmocka_unit_test(primitive_rsc),
 147                 cmocka_unit_test(group_rsc),
 148                 cmocka_unit_test(clone_rsc),
 149                 cmocka_unit_test(bundle_rsc))

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