LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_unit.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 71.9 % 32 23
Test Date: 2026-09-11 17:45:24 Functions: 80.0 % 5 4

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2025 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify
       6              :   it under the terms of the GNU General Public License as
       7              :   published by the Free Software Foundation; either version 3, or
       8              :   (at your option) any later version.
       9              : 
      10              :   TALER is distributed in the hope that it will be useful, but
      11              :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13              :   GNU General Public License for more details.
      14              : 
      15              :   You should have received a copy of the GNU General Public
      16              :   License along with TALER; see the file COPYING.  If not, see
      17              :   <http://www.gnu.org/licenses/>
      18              : */
      19              : /**
      20              :  * @file src/testing/testing_api_cmd_delete_unit.c
      21              :  * @brief command to test DELETE /private/units/$ID
      22              :  * @author Bohdan Potuzhnyi
      23              :  */
      24              : #include "platform.h"
      25              : struct DeleteUnitState;
      26              : #define TALER_MERCHANT_DELETE_PRIVATE_UNIT_RESULT_CLOSURE struct DeleteUnitState
      27              : #include <taler/taler_testing_lib.h>
      28              : #include "taler/taler_merchant_service.h"
      29              : #include "taler/taler_merchant_testing_lib.h"
      30              : #include <taler/merchant/delete-private-units-UNIT.h>
      31              : 
      32              : 
      33              : /**
      34              :  * State for a DELETE /private/units/$ID command.
      35              :  */
      36              : struct DeleteUnitState
      37              : {
      38              :   /**
      39              :    * In-flight request handle.
      40              :    */
      41              :   struct TALER_MERCHANT_DeletePrivateUnitHandle *udh;
      42              : 
      43              :   /**
      44              :    * Interpreter context.
      45              :    */
      46              :   struct TALER_TESTING_Interpreter *is;
      47              : 
      48              :   /**
      49              :    * Merchant backend base URL.
      50              :    */
      51              :   const char *merchant_url;
      52              : 
      53              :   /**
      54              :    * Unit identifier to delete.
      55              :    */
      56              :   const char *unit_id;
      57              : 
      58              :   /**
      59              :    * Expected HTTP status.
      60              :    */
      61              :   unsigned int http_status;
      62              : };
      63              : 
      64              : 
      65              : /**
      66              :  * Completion callback.
      67              :  */
      68              : static void
      69            6 : delete_unit_cb (struct DeleteUnitState *dus,
      70              :                 const struct TALER_MERCHANT_DeletePrivateUnitResponse *dur)
      71              : {
      72              : 
      73            6 :   dus->udh = NULL;
      74            6 :   if (dus->http_status != dur->hr.http_status)
      75              :   {
      76            0 :     TALER_TESTING_unexpected_status_with_body (dus->is,
      77              :                                                dur->hr.http_status,
      78              :                                                dus->http_status,
      79              :                                                dur->hr.reply);
      80            0 :     return;
      81              :   }
      82            6 :   TALER_TESTING_interpreter_next (dus->is);
      83              : }
      84              : 
      85              : 
      86              : /**
      87              :  * Issue DELETE request.
      88              :  */
      89              : static void
      90            6 : delete_unit_run (void *cls,
      91              :                  const struct TALER_TESTING_Command *cmd,
      92              :                  struct TALER_TESTING_Interpreter *is)
      93              : {
      94            6 :   struct DeleteUnitState *dus = cls;
      95              : 
      96            6 :   dus->is = is;
      97            6 :   dus->udh = TALER_MERCHANT_delete_private_unit_create (
      98              :     TALER_TESTING_interpreter_get_context (is),
      99              :     dus->merchant_url,
     100              :     dus->unit_id);
     101              :   {
     102              :     enum TALER_ErrorCode ec;
     103              : 
     104            6 :     ec = TALER_MERCHANT_delete_private_unit_start (dus->udh,
     105              :                                                    &delete_unit_cb,
     106              :                                                    dus);
     107            6 :     GNUNET_assert (TALER_EC_NONE == ec);
     108              :   }
     109            6 : }
     110              : 
     111              : 
     112              : /**
     113              :  * Provide traits.
     114              :  */
     115              : static enum GNUNET_GenericReturnValue
     116            0 : delete_unit_traits (void *cls,
     117              :                     const void **ret,
     118              :                     const char *trait,
     119              :                     unsigned int index)
     120              : {
     121            0 :   struct DeleteUnitState *dus = cls;
     122              :   struct TALER_TESTING_Trait traits[] = {
     123            0 :     TALER_TESTING_make_trait_unit_id (dus->unit_id),
     124            0 :     TALER_TESTING_trait_end ()
     125              :   };
     126              : 
     127            0 :   return TALER_TESTING_get_trait (traits,
     128              :                                   ret,
     129              :                                   trait,
     130              :                                   index);
     131              : }
     132              : 
     133              : 
     134              : /**
     135              :  * Cleanup.
     136              :  */
     137              : static void
     138            6 : delete_unit_cleanup (void *cls,
     139              :                      const struct TALER_TESTING_Command *cmd)
     140              : {
     141            6 :   struct DeleteUnitState *dus = cls;
     142              : 
     143            6 :   if (NULL != dus->udh)
     144              :   {
     145            0 :     TALER_MERCHANT_delete_private_unit_cancel (dus->udh);
     146            0 :     dus->udh = NULL;
     147              :   }
     148            6 :   GNUNET_free (dus);
     149            6 : }
     150              : 
     151              : 
     152              : struct TALER_TESTING_Command
     153            6 : TALER_TESTING_cmd_merchant_delete_unit (const char *label,
     154              :                                         const char *merchant_url,
     155              :                                         const char *unit_id,
     156              :                                         unsigned int http_status)
     157              : {
     158              :   struct DeleteUnitState *dus;
     159              : 
     160            6 :   dus = GNUNET_new (struct DeleteUnitState);
     161            6 :   dus->merchant_url = merchant_url;
     162            6 :   dus->unit_id = unit_id;
     163            6 :   dus->http_status = http_status;
     164              : 
     165              :   {
     166            6 :     struct TALER_TESTING_Command cmd = {
     167              :       .cls = dus,
     168              :       .label = label,
     169              :       .run = &delete_unit_run,
     170              :       .cleanup = &delete_unit_cleanup,
     171              :       .traits = &delete_unit_traits
     172              :     };
     173              : 
     174            6 :     return cmd;
     175              :   }
     176              : }
     177              : 
     178              : 
     179              : /* end of testing_api_cmd_delete_unit.c */
        

Generated by: LCOV version 2.0-1