LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_donau_instances.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 67.5 % 40 27
Test Date: 2026-09-11 17:45:24 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2024 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify it under the
       6              :   terms of the GNU Lesser General Public License as published by the Free Software
       7              :   Foundation; either version 2.1, or (at your option) any later version.
       8              : 
       9              :   TALER is distributed in the hope that it will be useful,
      10              :   but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      11              :   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
      12              : 
      13              :   You should have received a copy of the GNU Lesser General Public License along with TALER;
      14              :   see the file COPYING.LGPL.  If not, see <http://www.gnu.org/licenses/>
      15              :  */
      16              : /**
      17              :  * @file src/testing/testing_api_cmd_delete_donau_instances.c
      18              :  * @brief Command to test DELETE /donau/$charity_id request
      19              :  * @author Bohdan Potuzhnyi
      20              :  * @author Vlada Svirsh
      21              :  */
      22              : 
      23              : #include "platform.h"
      24              : struct DeleteDonauState;
      25              : #define TALER_MERCHANT_DELETE_PRIVATE_DONAU_RESULT_CLOSURE struct DeleteDonauState
      26              : #include <taler/taler_testing_lib.h>
      27              : #include "taler/taler_merchant_service.h"
      28              : #include "taler/taler_merchant_testing_lib.h"
      29              : #include <taler/merchant/delete-private-donau-DONAU_SERIAL.h>
      30              : 
      31              : /**
      32              :  * State for DELETE /donau/$charity_id testing command.
      33              :  */
      34              : struct DeleteDonauState
      35              : {
      36              :   /**
      37              :    * Handle for a DELETE /donau request.
      38              :    */
      39              :   struct TALER_MERCHANT_DeletePrivateDonauHandle *ddh;
      40              : 
      41              :   /**
      42              :    * The interpreter state.
      43              :    */
      44              :   struct TALER_TESTING_Interpreter *is;
      45              : 
      46              :   /**
      47              :    * Base URL of the Donau service.
      48              :    */
      49              :   const char *url;
      50              : 
      51              :   /**
      52              :    * Charity ID to delete.
      53              :    */
      54              :   uint64_t charity_id;
      55              : 
      56              :   /**
      57              :    * Expected HTTP response code.
      58              :    */
      59              :   unsigned int expected_http_status;
      60              : };
      61              : 
      62              : /**
      63              :  * Callback for DELETE /donau/$charity_id operation.
      64              :  *
      65              :  * @param cls closure for this function
      66              :  * @param ddr HTTP response details
      67              :  */
      68              : static void
      69            2 : delete_donau_cb (struct DeleteDonauState *dds,
      70              :                  const struct TALER_MERCHANT_DeletePrivateDonauResponse *ddr)
      71              : {
      72              : 
      73            2 :   dds->ddh = NULL;
      74              : 
      75            2 :   if (dds->expected_http_status != ddr->hr.http_status)
      76              :   {
      77            0 :     TALER_TESTING_unexpected_status_with_body (
      78              :       dds->is,
      79              :       ddr->hr.http_status,
      80              :       dds->expected_http_status,
      81              :       ddr->hr.reply);
      82            0 :     TALER_TESTING_interpreter_fail (dds->is);
      83            0 :     return;
      84              :   }
      85              : 
      86            2 :   switch (ddr->hr.http_status)
      87              :   {
      88            2 :   case MHD_HTTP_NO_CONTENT:
      89            2 :     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
      90              :                 "DELETE /donau succeeded\n");
      91            2 :     break;
      92            0 :   case MHD_HTTP_NOT_FOUND:
      93            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
      94              :                 "DELETE /donau: Charity not found\n");
      95            0 :     break;
      96            0 :   case MHD_HTTP_UNAUTHORIZED:
      97            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
      98              :                 "DELETE /donau: Unauthorized access\n");
      99            0 :     break;
     100            0 :   default:
     101            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     102              :                 "Unhandled HTTP status %u\n",
     103              :                 ddr->hr.http_status);
     104              :   }
     105              : 
     106            2 :   TALER_TESTING_interpreter_next (dds->is);
     107              : }
     108              : 
     109              : 
     110              : /**
     111              :  * Run the DELETE /donau/$charity_id test command.
     112              :  *
     113              :  * @param cls closure.
     114              :  * @param cmd command being run now.
     115              :  * @param is interpreter state.
     116              :  */
     117              : static void
     118            2 : delete_donau_run (void *cls,
     119              :                   const struct TALER_TESTING_Command *cmd,
     120              :                   struct TALER_TESTING_Interpreter *is)
     121              : {
     122            2 :   struct DeleteDonauState *dds = cls;
     123              : 
     124            2 :   dds->is = is;
     125            2 :   dds->ddh = TALER_MERCHANT_delete_private_donau_create (
     126              :     TALER_TESTING_interpreter_get_context (is),
     127              :     dds->url,
     128              :     dds->charity_id);
     129              :   {
     130              :     enum TALER_ErrorCode ec;
     131              : 
     132            2 :     ec = TALER_MERCHANT_delete_private_donau_start (dds->ddh,
     133              :                                                     &delete_donau_cb,
     134              :                                                     dds);
     135            2 :     GNUNET_assert (TALER_EC_NONE == ec);
     136              :   }
     137            2 : }
     138              : 
     139              : 
     140              : /**
     141              :  * Clean up state for DELETE /donau/$charity_id command.
     142              :  *
     143              :  * @param cls closure.
     144              :  * @param cmd command being run.
     145              :  */
     146              : static void
     147            2 : delete_donau_cleanup (void *cls,
     148              :                       const struct TALER_TESTING_Command *cmd)
     149              : {
     150            2 :   struct DeleteDonauState *dds = cls;
     151              : 
     152            2 :   if (NULL != dds->ddh)
     153              :   {
     154            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     155              :                 "DELETE /donau/$charity_id operation did not complete\n");
     156            0 :     TALER_MERCHANT_delete_private_donau_cancel (dds->ddh);
     157              :   }
     158            2 :   GNUNET_free (dds);
     159            2 : }
     160              : 
     161              : 
     162              : /**
     163              :  * Create a DELETE /donau/$charity_id testing command.
     164              :  */
     165              : struct TALER_TESTING_Command
     166            2 : TALER_TESTING_cmd_merchant_delete_donau_instance (const char *label,
     167              :                                                   const char *url,
     168              :                                                   uint64_t charity_id,
     169              :                                                   unsigned int
     170              :                                                   expected_http_status)
     171              : {
     172            2 :   struct DeleteDonauState *dds = GNUNET_new (struct DeleteDonauState);
     173              : 
     174            2 :   dds->url = url;
     175            2 :   dds->charity_id = charity_id;
     176            2 :   dds->expected_http_status = expected_http_status;
     177              : 
     178              :   {
     179            2 :     struct TALER_TESTING_Command cmd = {
     180              :       .cls = dds,
     181              :       .label = label,
     182              :       .run = &delete_donau_run,
     183              :       .cleanup = &delete_donau_cleanup
     184              :     };
     185              : 
     186            2 :     return cmd;
     187              :   }
     188              : 
     189              : }
        

Generated by: LCOV version 2.0-1