root/lib/common/tests/agents/crm_parse_agent_spec_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. all_params_null
  2. no_prov_or_type
  3. no_type
  4. get_std_and_ty
  5. get_all_values
  6. get_systemd_values

   1 /*
   2  * Copyright 2022-2023 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 #include <crm/common/agents.h>
  14 
  15 static void
  16 all_params_null(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  17     assert_int_equal(crm_parse_agent_spec(NULL, NULL, NULL, NULL), -EINVAL);
  18     assert_int_equal(crm_parse_agent_spec("", NULL, NULL, NULL), -EINVAL);
  19     assert_int_equal(crm_parse_agent_spec(":", NULL, NULL, NULL), -EINVAL);
  20     assert_int_equal(crm_parse_agent_spec("::", NULL, NULL, NULL), -EINVAL);
  21 }
  22 
  23 static void
  24 no_prov_or_type(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  25     char *std = NULL;
  26     char *prov = NULL;
  27     char *ty = NULL;
  28 
  29     assert_int_equal(crm_parse_agent_spec("ocf", &std, &prov, &ty), -EINVAL);
  30     assert_int_equal(crm_parse_agent_spec("ocf:", &std, &prov, &ty), -EINVAL);
  31     assert_int_equal(crm_parse_agent_spec("ocf::", &std, &prov, &ty), -EINVAL);
  32 }
  33 
  34 static void
  35 no_type(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  36     char *std = NULL;
  37     char *prov = NULL;
  38     char *ty = NULL;
  39 
  40     assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:", &std, &prov, &ty), -EINVAL);
  41 }
  42 
  43 static void
  44 get_std_and_ty(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  45     char *std = NULL;
  46     char *prov = NULL;
  47     char *ty = NULL;
  48 
  49     assert_int_equal(crm_parse_agent_spec("stonith:fence_xvm", &std, &prov, &ty), pcmk_ok);
  50     assert_string_equal(std, "stonith");
  51     assert_null(prov);
  52     assert_string_equal(ty, "fence_xvm");
  53 
  54     free(std);
  55     free(ty);
  56 }
  57 
  58 static void
  59 get_all_values(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  60     char *std = NULL;
  61     char *prov = NULL;
  62     char *ty = NULL;
  63 
  64     assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:ping", &std, &prov, &ty), pcmk_ok);
  65     assert_string_equal(std, "ocf");
  66     assert_string_equal(prov, "pacemaker");
  67     assert_string_equal(ty, "ping");
  68 
  69     free(std);
  70     free(prov);
  71     free(ty);
  72 }
  73 
  74 static void
  75 get_systemd_values(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  76     char *std = NULL;
  77     char *prov = NULL;
  78     char *ty = NULL;
  79 
  80     assert_int_equal(crm_parse_agent_spec("systemd:UNIT@A:B", &std, &prov, &ty), pcmk_ok);
  81     assert_string_equal(std, "systemd");
  82     assert_null(prov);
  83     assert_string_equal(ty, "UNIT@A:B");
  84 
  85     free(std);
  86     free(ty);
  87 }
  88 
  89 PCMK__UNIT_TEST(NULL, NULL,
  90                 cmocka_unit_test(all_params_null),
  91                 cmocka_unit_test(no_prov_or_type),
  92                 cmocka_unit_test(no_type),
  93                 cmocka_unit_test(get_std_and_ty),
  94                 cmocka_unit_test(get_all_values),
  95                 cmocka_unit_test(get_systemd_values))

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