root/lib/common/tests/operations/parse_op_key_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. basic
  2. colon_in_rsc
  3. dashes_in_rsc
  4. migrate_to_from
  5. pre_post
  6. skip_rsc
  7. skip_ty
  8. skip_ms
  9. empty_input
  10. malformed_input

   1 /*
   2  * Copyright 2020-2021 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 
  14 #include <glib.h>
  15 
  16 static void
  17 basic(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19     char *rsc = NULL;
  20     char *ty = NULL;
  21     guint ms = 0;
  22 
  23     assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms));
  24     assert_string_equal(rsc, "Fencing");
  25     assert_string_equal(ty, "monitor");
  26     assert_int_equal(ms, 60000);
  27     free(rsc);
  28     free(ty);
  29 }
  30 
  31 static void
  32 colon_in_rsc(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34     char *rsc = NULL;
  35     char *ty = NULL;
  36     guint ms = 0;
  37 
  38     assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms));
  39     assert_string_equal(rsc, "ClusterIP:0");
  40     assert_string_equal(ty, "start");
  41     assert_int_equal(ms, 0);
  42     free(rsc);
  43     free(ty);
  44 
  45     assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms));
  46     assert_string_equal(rsc, "imagestoreclone:1");
  47     assert_string_equal(ty, "post_notify_stop");
  48     assert_int_equal(ms, 0);
  49     free(rsc);
  50     free(ty);
  51 }
  52 
  53 static void
  54 dashes_in_rsc(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56     char *rsc = NULL;
  57     char *ty = NULL;
  58     guint ms = 0;
  59 
  60     assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms));
  61     assert_string_equal(rsc, "httpd-bundle-0");
  62     assert_string_equal(ty, "monitor");
  63     assert_int_equal(ms, 30000);
  64     free(rsc);
  65     free(ty);
  66 
  67     assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms));
  68     assert_string_equal(rsc, "httpd-bundle-ip-192.168.122.132");
  69     assert_string_equal(ty, "start");
  70     assert_int_equal(ms, 0);
  71     free(rsc);
  72     free(ty);
  73 }
  74 
  75 static void
  76 migrate_to_from(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  77 {
  78     char *rsc = NULL;
  79     char *ty = NULL;
  80     guint ms = 0;
  81 
  82     assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms));
  83     assert_string_equal(rsc, "vm");
  84     assert_string_equal(ty, "migrate_from");
  85     assert_int_equal(ms, 0);
  86     free(rsc);
  87     free(ty);
  88 
  89     assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms));
  90     assert_string_equal(rsc, "vm");
  91     assert_string_equal(ty, "migrate_to");
  92     assert_int_equal(ms, 0);
  93     free(rsc);
  94     free(ty);
  95 
  96     assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms));
  97     assert_string_equal(rsc, "vm_idcc_devel");
  98     assert_string_equal(ty, "migrate_to");
  99     assert_int_equal(ms, 0);
 100     free(rsc);
 101     free(ty);
 102 }
 103 
 104 static void
 105 pre_post(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 106 {
 107     char *rsc = NULL;
 108     char *ty = NULL;
 109     guint ms = 0;
 110 
 111     assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms));
 112     assert_string_equal(rsc, "rsc_drbd_7788:1");
 113     assert_string_equal(ty, "post_notify_start");
 114     assert_int_equal(ms, 0);
 115     free(rsc);
 116     free(ty);
 117 
 118     assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms));
 119     assert_string_equal(rsc, "rabbitmq-bundle-clone");
 120     assert_string_equal(ty, "pre_notify_stop");
 121     assert_int_equal(ms, 0);
 122     free(rsc);
 123     free(ty);
 124 
 125     assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms));
 126     assert_string_equal(rsc, "post_notify");
 127     assert_string_equal(ty, "start");
 128     assert_int_equal(ms, 0);
 129     free(rsc);
 130     free(ty);
 131 }
 132 
 133 static void
 134 skip_rsc(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 135 {
 136     char *ty = NULL;
 137     guint ms = 0;
 138 
 139     assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms));
 140     assert_string_equal(ty, "monitor");
 141     assert_int_equal(ms, 60000);
 142     free(ty);
 143 }
 144 
 145 static void
 146 skip_ty(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 147 {
 148     char *rsc = NULL;
 149     guint ms = 0;
 150 
 151     assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms));
 152     assert_string_equal(rsc, "Fencing");
 153     assert_int_equal(ms, 60000);
 154     free(rsc);
 155 }
 156 
 157 static void
 158 skip_ms(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 159 {
 160     char *rsc = NULL;
 161     char *ty = NULL;
 162 
 163     assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL));
 164     assert_string_equal(rsc, "Fencing");
 165     assert_string_equal(ty, "monitor");
 166     free(rsc);
 167     free(ty);
 168 }
 169 
 170 static void
 171 empty_input(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 172 {
 173     char *rsc = NULL;
 174     char *ty = NULL;
 175     guint ms = 0;
 176 
 177     assert_false(parse_op_key("", &rsc, &ty, &ms));
 178     assert_null(rsc);
 179     assert_null(ty);
 180     assert_int_equal(ms, 0);
 181 
 182     assert_false(parse_op_key(NULL, &rsc, &ty, &ms));
 183     assert_null(rsc);
 184     assert_null(ty);
 185     assert_int_equal(ms, 0);
 186 }
 187 
 188 static void
 189 malformed_input(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 190 {
 191     char *rsc = NULL;
 192     char *ty = NULL;
 193     guint ms = 0;
 194 
 195     assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms));
 196     assert_null(rsc);
 197     assert_null(ty);
 198     assert_int_equal(ms, 0);
 199 
 200     assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms));
 201     assert_null(rsc);
 202     assert_null(ty);
 203     assert_int_equal(ms, 0);
 204 
 205     assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms));
 206     assert_null(rsc);
 207     assert_null(ty);
 208     assert_int_equal(ms, 0);
 209 }
 210 
 211 PCMK__UNIT_TEST(NULL, NULL,
 212                 cmocka_unit_test(basic),
 213                 cmocka_unit_test(colon_in_rsc),
 214                 cmocka_unit_test(dashes_in_rsc),
 215                 cmocka_unit_test(migrate_to_from),
 216                 cmocka_unit_test(pre_post),
 217                 cmocka_unit_test(skip_rsc),
 218                 cmocka_unit_test(skip_ty),
 219                 cmocka_unit_test(skip_ms),
 220                 cmocka_unit_test(empty_input),
 221                 cmocka_unit_test(malformed_input))

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