root/lib/pacemaker/tests/pcmk_ticket/pcmk_ticket_info_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. setup_test
  2. teardown_test
  3. bad_arguments
  4. unknown_ticket
  5. all_tickets
  6. single_ticket

   1 /*
   2  * Copyright 2024 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 
  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 int
  20 setup_test(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  21 {
  22     cib_path = pcmk__cib_test_copy_cib("tickets.xml");
  23 
  24     if (cib_path == NULL) {
  25         return -1;
  26     }
  27 
  28     return 0;
  29 }
  30 
  31 static int
  32 teardown_test(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34     pcmk__cib_test_cleanup(cib_path);
  35     cib_path = NULL;
  36     return 0;
  37 }
  38 
  39 static void
  40 bad_arguments(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42     assert_int_equal(pcmk_ticket_info(NULL, "ticketA"), EINVAL);
  43 }
  44 
  45 static void
  46 unknown_ticket(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48     xmlNode *xml = NULL;
  49 
  50     assert_int_equal(pcmk_ticket_info(&xml, "XYZ"), ENXIO);
  51     pcmk__assert_validates(xml);
  52     free_xml(xml);
  53 }
  54 
  55 static void
  56 all_tickets(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  57 {
  58     xmlNode *node = NULL;
  59     xmlXPathObject *xpath_obj = NULL;
  60     xmlNode *xml = NULL;
  61 
  62     assert_int_equal(pcmk_ticket_info(&xml, NULL), pcmk_rc_ok);
  63     pcmk__assert_validates(xml);
  64 
  65     /* Verify that the XML result has three <ticket> elements, with the attributes
  66      * we expect.  The input has four tickets, but when they are loaded into the
  67      * scheduler's hash table, the duplicate IDs will collide leaving us with
  68      * three.
  69      */
  70     xpath_obj = xpath_search(xml, "//" PCMK_XE_PACEMAKER_RESULT "/" PCMK_XE_TICKETS "/" PCMK_XE_TICKET);
  71     assert_int_equal(numXpathResults(xpath_obj), 3);
  72     freeXpathObject(xpath_obj);
  73 
  74     xpath_obj = xpath_search(xml, "//" PCMK_XE_PACEMAKER_RESULT "/" PCMK_XE_TICKETS
  75                                   "/" PCMK_XE_TICKET "[@" PCMK_XA_ID "=\"ticketA\"]");
  76 
  77     node = getXpathResult(xpath_obj, 0);
  78     assert_string_equal(crm_element_value(node, PCMK_XA_STATUS), PCMK_VALUE_REVOKED);
  79     assert_string_equal(crm_element_value(node, PCMK__XA_GRANTED), "false");
  80     assert_string_equal(crm_element_value(node, PCMK_XA_STANDBY), PCMK_VALUE_FALSE);
  81     assert_string_equal(crm_element_value(node, "owner"), "1");
  82     freeXpathObject(xpath_obj);
  83 
  84     xpath_obj = xpath_search(xml, "//" PCMK_XE_PACEMAKER_RESULT "/" PCMK_XE_TICKETS
  85                                   "/" PCMK_XE_TICKET "[@" PCMK_XA_ID "=\"ticketB\"]");
  86 
  87     node = getXpathResult(xpath_obj, 0);
  88     assert_string_equal(crm_element_value(node, PCMK_XA_STATUS), PCMK_VALUE_GRANTED);
  89     assert_string_equal(crm_element_value(node, PCMK__XA_GRANTED), "true");
  90     assert_string_equal(crm_element_value(node, PCMK_XA_STANDBY), PCMK_VALUE_FALSE);
  91     assert_null(crm_element_value(node, "owner"));
  92     freeXpathObject(xpath_obj);
  93 
  94     xpath_obj = xpath_search(xml, "//" PCMK_XE_PACEMAKER_RESULT "/" PCMK_XE_TICKETS
  95                                   "/" PCMK_XE_TICKET "[@" PCMK_XA_ID "=\"ticketC\"]");
  96 
  97     node = getXpathResult(xpath_obj, 0);
  98     assert_string_equal(crm_element_value(node, PCMK_XA_STATUS), PCMK_VALUE_GRANTED);
  99     assert_string_equal(crm_element_value(node, PCMK__XA_GRANTED), "true");
 100     assert_string_equal(crm_element_value(node, PCMK_XA_STANDBY), PCMK_VALUE_FALSE);
 101     assert_null(crm_element_value(node, "owner"));
 102 
 103     freeXpathObject(xpath_obj);
 104     free_xml(xml);
 105 }
 106 
 107 static void
 108 single_ticket(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 109 {
 110     xmlNode *node = NULL;
 111     xmlXPathObject *xpath_obj = NULL;
 112     xmlNode *xml = NULL;
 113 
 114     assert_int_equal(pcmk_ticket_info(&xml, "ticketA"), pcmk_rc_ok);
 115     pcmk__assert_validates(xml);
 116 
 117     /* Verify that the XML result has only one <ticket>, with the attributes
 118      * we expect.
 119      */
 120     xpath_obj = xpath_search(xml, "//" PCMK_XE_PACEMAKER_RESULT "/" PCMK_XE_TICKETS
 121                                   "/" PCMK_XE_TICKET "[@" PCMK_XA_ID "=\"ticketA\"]");
 122     assert_int_equal(numXpathResults(xpath_obj), 1);
 123 
 124     node = getXpathResult(xpath_obj, 0);
 125     assert_string_equal(crm_element_value(node, PCMK_XA_STATUS), PCMK_VALUE_REVOKED);
 126     assert_string_equal(crm_element_value(node, PCMK__XA_GRANTED), "false");
 127     assert_string_equal(crm_element_value(node, PCMK_XA_STANDBY), PCMK_VALUE_FALSE);
 128     assert_string_equal(crm_element_value(node, "owner"), "1");
 129 
 130     freeXpathObject(xpath_obj);
 131     free_xml(xml);
 132 }
 133 
 134 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
 135                 cmocka_unit_test_setup_teardown(bad_arguments, setup_test, teardown_test),
 136                 cmocka_unit_test_setup_teardown(unknown_ticket, setup_test, teardown_test),
 137                 cmocka_unit_test_setup_teardown(all_tickets, setup_test, teardown_test),
 138                 cmocka_unit_test_setup_teardown(single_ticket, setup_test, teardown_test))

/* [previous][next][first][last][top][bottom][index][help] */