pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
crm_parse_agent_spec_test.c
Go to the documentation of this file.
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 
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  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) {
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) {
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) {
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) {
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))
API related to resource agents.
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type)
Parse a "standard[:provider]:type" agent specification.
Definition: agents.c:125
#define pcmk_ok
Definition: results.h:69