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