pacemaker  2.1.6-802a72226b
Scalable High-Availability cluster resource manager
crm_parse_agent_spec_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 General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 #include <crm/common/agents.h>
14 
15 static void
16 all_params_null(void **state) {
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) {
25  assert_int_equal(crm_parse_agent_spec("ocf", NULL, NULL, NULL), -EINVAL);
26  assert_int_equal(crm_parse_agent_spec("ocf:", NULL, NULL, NULL), -EINVAL);
27  assert_int_equal(crm_parse_agent_spec("ocf::", NULL, NULL, NULL), -EINVAL);
28 }
29 
30 static void
31 no_type(void **state) {
32  assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:", NULL, NULL, NULL), -EINVAL);
33 }
34 
35 static void
36 get_std_and_ty(void **state) {
37  char *std = NULL;
38  char *prov = NULL;
39  char *ty = NULL;
40 
41  assert_int_equal(crm_parse_agent_spec("stonith:fence_xvm", &std, &prov, &ty), pcmk_ok);
42  assert_string_equal(std, "stonith");
43  assert_null(prov);
44  assert_string_equal(ty, "fence_xvm");
45 
46  free(std);
47  free(ty);
48 }
49 
50 static void
51 get_all_values(void **state) {
52  char *std = NULL;
53  char *prov = NULL;
54  char *ty = NULL;
55 
56  assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:ping", &std, &prov, &ty), pcmk_ok);
57  assert_string_equal(std, "ocf");
58  assert_string_equal(prov, "pacemaker");
59  assert_string_equal(ty, "ping");
60 
61  free(std);
62  free(prov);
63  free(ty);
64 }
65 
66 static void
67 get_systemd_values(void **state) {
68  char *std = NULL;
69  char *prov = NULL;
70  char *ty = NULL;
71 
72  assert_int_equal(crm_parse_agent_spec("systemd:UNIT@A:B", &std, &prov, &ty), pcmk_ok);
73  assert_string_equal(std, "systemd");
74  assert_null(prov);
75  assert_string_equal(ty, "UNIT@A:B");
76 
77  free(std);
78  free(ty);
79 }
80 
81 PCMK__UNIT_TEST(NULL, NULL,
82  cmocka_unit_test(all_params_null),
83  cmocka_unit_test(no_prov_or_type),
84  cmocka_unit_test(no_type),
85  cmocka_unit_test(get_std_and_ty),
86  cmocka_unit_test(get_all_values),
87  cmocka_unit_test(get_systemd_values))
API related to resource agents.
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type)
Parse a "standard[:provider]:type" agent specification.
Definition: agents.c:124
#define pcmk_ok
Definition: results.h:68