This source file includes following definitions.
- cib_not_connected
- setup_test
- teardown_test
- bad_arguments
- unknown_ticket
- ticket_granted
- ticket_exists
- force_delete_ticket
- duplicate_tickets
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_ticket_delete(&xml, "ticketA", false), 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("tickets.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_arguments(void **state)
55 {
56 xmlNode *xml = NULL;
57
58 assert_int_equal(pcmk_ticket_delete(NULL, "ticketA", false), EINVAL);
59
60 assert_int_equal(pcmk_ticket_delete(&xml, NULL, false), EINVAL);
61 pcmk__assert_validates(xml);
62 free_xml(xml);
63 }
64
65 static void
66 unknown_ticket(void **state)
67 {
68 xmlNode *xml = NULL;
69
70 assert_int_equal(pcmk_ticket_delete(&xml, "XYZ", false), ENXIO);
71 pcmk__assert_validates(xml);
72 free_xml(xml);
73 xml = NULL;
74
75 assert_int_equal(pcmk_ticket_delete(&xml, "XYZ", true), pcmk_rc_ok);
76 pcmk__assert_validates(xml);
77 free_xml(xml);
78 }
79
80 static void
81 ticket_granted(void **state)
82 {
83 xmlNode *xml = NULL;
84
85 assert_int_equal(pcmk_ticket_delete(&xml, "ticketB", false), EACCES);
86 pcmk__assert_validates(xml);
87 free_xml(xml);
88 }
89
90 static void
91 ticket_exists(void **state)
92 {
93 xmlNode *xml = NULL;
94 xmlNode *xml_search = NULL;
95 cib_t *cib;
96
97 assert_int_equal(pcmk_ticket_delete(&xml, "ticketA", false), pcmk_rc_ok);
98 pcmk__assert_validates(xml);
99
100
101 cib = cib_new();
102 cib->cmds->signon(cib, crm_system_name, cib_command);
103 cib->cmds->query(cib, "//" PCMK__XE_TICKET_STATE "[@" PCMK_XA_ID "=\"ticketA\"]",
104 &xml_search, cib_xpath | cib_scope_local);
105 assert_null(xml_search);
106
107 free_xml(xml);
108 cib__clean_up_connection(&cib);
109 }
110
111 static void
112 force_delete_ticket(void **state)
113 {
114 xmlNode *xml = NULL;
115 xmlNode *xml_search = NULL;
116 cib_t *cib;
117
118 assert_int_equal(pcmk_ticket_delete(&xml, "ticketB", true), pcmk_rc_ok);
119 pcmk__assert_validates(xml);
120
121
122 cib = cib_new();
123 cib->cmds->signon(cib, crm_system_name, cib_command);
124 cib->cmds->query(cib, "//" PCMK__XE_TICKET_STATE "[@" PCMK_XA_ID "=\"ticketB\"]",
125 &xml_search, cib_xpath | cib_scope_local);
126 assert_null(xml_search);
127
128 free_xml(xml);
129 cib__clean_up_connection(&cib);
130 }
131
132 static void
133 duplicate_tickets(void **state)
134 {
135 xmlNode *xml = NULL;
136 xmlNode *xml_search = NULL;
137 cib_t *cib;
138
139 assert_int_equal(pcmk_ticket_delete(&xml, "ticketC", true), pcmk_rc_ok);
140 pcmk__assert_validates(xml);
141
142
143 cib = cib_new();
144 cib->cmds->signon(cib, crm_system_name, cib_command);
145 cib->cmds->query(cib, "//" PCMK__XE_TICKET_STATE "[@" PCMK_XA_ID "=\"ticketC\"]",
146 &xml_search, cib_xpath | cib_scope_local);
147
148 assert_null(xml_search);
149
150 free_xml(xml);
151 cib__clean_up_connection(&cib);
152 }
153
154
155
156
157
158
159
160
161
162
163 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
164 cmocka_unit_test(cib_not_connected),
165 cmocka_unit_test_setup_teardown(bad_arguments, setup_test, teardown_test),
166 cmocka_unit_test_setup_teardown(unknown_ticket, setup_test, teardown_test),
167 cmocka_unit_test_setup_teardown(ticket_granted, setup_test, teardown_test),
168 cmocka_unit_test_setup_teardown(ticket_exists, setup_test, teardown_test),
169 cmocka_unit_test_setup_teardown(force_delete_ticket, setup_test, teardown_test),
170 cmocka_unit_test_setup_teardown(duplicate_tickets, setup_test, teardown_test))