This source file includes following definitions.
- cib_not_connected
- setup_test
- teardown_test
- bad_input
- find_rsc
- incorrect_type
- correct_type
- unknown_resource
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/cib/internal.h>
13 #include <crm/common/unittest_internal.h>
14 #include <crm/common/xml.h>
15 #include <pacemaker.h>
16
17 static char *cib_path = NULL;
18
19 static void
20 cib_not_connected(void **state)
21 {
22 xmlNode *xml = NULL;
23
24
25
26
27
28 assert_int_equal(pcmk_resource_delete(&xml, "rsc", "primitive"), ENOTCONN);
29 pcmk__assert_validates(xml);
30 free_xml(xml);
31 }
32
33 static int
34 setup_test(void **state)
35 {
36 cib_path = pcmk__cib_test_copy_cib("crm_mon.xml");
37
38 if (cib_path == NULL) {
39 return -1;
40 }
41
42 return 0;
43 }
44
45 static int
46 teardown_test(void **state)
47 {
48 pcmk__cib_test_cleanup(cib_path);
49 cib_path = NULL;
50 return 0;
51 }
52
53 static void
54 bad_input(void **state)
55 {
56 xmlNode *xml = NULL;
57
58
59
60
61 assert_int_equal(pcmk_resource_delete(&xml, "Fencing", NULL), EINVAL);
62 pcmk__assert_validates(xml);
63 free_xml(xml);
64 xml = NULL;
65
66 assert_int_equal(pcmk_resource_delete(&xml, NULL, "primitive"), EINVAL);
67 pcmk__assert_validates(xml);
68 free_xml(xml);
69 }
70
71 static xmlNode *
72 find_rsc(const char *rsc)
73 {
74 GString *xpath = g_string_sized_new(1024);
75 xmlNode *xml_search = NULL;
76 cib_t *cib = NULL;
77
78 cib = cib_new();
79 cib->cmds->signon(cib, crm_system_name, cib_command);
80
81 pcmk__g_strcat(xpath,
82 pcmk_cib_xpath_for(PCMK_XE_RESOURCES),
83 "//*[@" PCMK_XA_ID "=\"", rsc, "\"]", NULL);
84
85 cib->cmds->query(cib, (const char *) xpath->str, &xml_search,
86 cib_xpath|cib_scope_local);
87
88 g_string_free(xpath, TRUE);
89 cib__clean_up_connection(&cib);
90 return xml_search;
91 }
92
93 static void
94 incorrect_type(void **state)
95 {
96 xmlNode *xml = NULL;
97 xmlNode *result = NULL;
98
99
100
101
102
103 assert_int_equal(pcmk_resource_delete(&xml, "Fencing", "clone"), pcmk_rc_ok);
104 pcmk__assert_validates(xml);
105 free_xml(xml);
106
107 result = find_rsc("Fencing");
108 assert_non_null(result);
109
110 free_xml(result);
111 }
112
113 static void
114 correct_type(void **state)
115 {
116 xmlNode *xml = NULL;
117 xmlNode *result = NULL;
118
119 assert_int_equal(pcmk_resource_delete(&xml, "Fencing", "primitive"), pcmk_rc_ok);
120 pcmk__assert_validates(xml);
121 free_xml(xml);
122
123 result = find_rsc("Fencing");
124 assert_null(result);
125
126 free_xml(result);
127 }
128
129 static void
130 unknown_resource(void **state)
131 {
132 xmlNode *xml = NULL;
133
134
135
136
137 assert_int_equal(pcmk_resource_delete(&xml, "no_such_resource", "primitive"), pcmk_rc_ok);
138 pcmk__assert_validates(xml);
139 free_xml(xml);
140 }
141
142
143
144
145
146
147
148
149
150
151 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
152 cmocka_unit_test(cib_not_connected),
153 cmocka_unit_test_setup_teardown(bad_input, setup_test, teardown_test),
154 cmocka_unit_test_setup_teardown(incorrect_type, setup_test, teardown_test),
155 cmocka_unit_test_setup_teardown(correct_type, setup_test, teardown_test),
156 cmocka_unit_test_setup_teardown(unknown_resource, setup_test, teardown_test))