LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_template.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 73.7 % 38 28
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) 2022 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_template.c
      21              :  * @brief command to test DELETE /templates/$ID
      22              :  * @author Priscilla HUANG
      23              :  */
      24              : #include "platform.h"
      25              : struct DeleteTemplateState;
      26              : #define TALER_MERCHANT_DELETE_PRIVATE_TEMPLATE_RESULT_CLOSURE struct DeleteTemplateState
      27              : #include <taler/taler_exchange_service.h>
      28              : #include <taler/taler_testing_lib.h>
      29              : #include "taler/taler_merchant_service.h"
      30              : #include "taler/taler_merchant_testing_lib.h"
      31              : #include <taler/merchant/delete-private-templates-TEMPLATE_ID.h>
      32              : 
      33              : 
      34              : /**
      35              :  * State of a "DELETE /templates/$ID" CMD.
      36              :  */
      37              : struct DeleteTemplateState
      38              : {
      39              : 
      40              :   /**
      41              :    * Handle for a "DELETE template" request.
      42              :    */
      43              :   struct TALER_MERCHANT_DeletePrivateTemplateHandle *tdh;
      44              : 
      45              :   /**
      46              :    * The interpreter state.
      47              :    */
      48              :   struct TALER_TESTING_Interpreter *is;
      49              : 
      50              :   /**
      51              :    * Base URL of the merchant serving the request.
      52              :    */
      53              :   const char *merchant_url;
      54              : 
      55              :   /**
      56              :    * ID of the template to run DELETE for.
      57              :    */
      58              :   const char *template_id;
      59              : 
      60              :   /**
      61              :    * Expected HTTP response code.
      62              :    */
      63              :   unsigned int http_status;
      64              : 
      65              : };
      66              : 
      67              : 
      68              : /**
      69              :  * Callback for a /delete/templates/$ID operation.
      70              :  *
      71              :  * @param cls closure for this function
      72              :  * @param dtr response being processed
      73              :  */
      74              : static void
      75            4 : delete_template_cb (struct DeleteTemplateState *dis,
      76              :                     const struct TALER_MERCHANT_DeletePrivateTemplateResponse *
      77              :                     dtr)
      78              : {
      79              : 
      80            4 :   dis->tdh = NULL;
      81            4 :   if (dis->http_status != dtr->hr.http_status)
      82              :   {
      83            0 :     TALER_TESTING_unexpected_status_with_body (dis->is,
      84              :                                                dtr->hr.http_status,
      85              :                                                dis->http_status,
      86              :                                                dtr->hr.reply);
      87            0 :     return;
      88              :   }
      89            4 :   switch (dtr->hr.http_status)
      90              :   {
      91            2 :   case MHD_HTTP_NO_CONTENT:
      92            2 :     break;
      93            0 :   case MHD_HTTP_UNAUTHORIZED:
      94            0 :     break;
      95            2 :   case MHD_HTTP_NOT_FOUND:
      96            2 :     break;
      97            0 :   case MHD_HTTP_CONFLICT:
      98            0 :     break;
      99            0 :   default:
     100            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     101              :                 "Unhandled HTTP status %u for DELETE template.\n",
     102              :                 dtr->hr.http_status);
     103              :   }
     104            4 :   TALER_TESTING_interpreter_next (dis->is);
     105              : }
     106              : 
     107              : 
     108              : /**
     109              :  * Run the "DELETE template" CMD.
     110              :  *
     111              :  *
     112              :  * @param cls closure.
     113              :  * @param cmd command being run now.
     114              :  * @param is interpreter state.
     115              :  */
     116              : static void
     117            4 : delete_template_run (void *cls,
     118              :                      const struct TALER_TESTING_Command *cmd,
     119              :                      struct TALER_TESTING_Interpreter *is)
     120              : {
     121            4 :   struct DeleteTemplateState *dis = cls;
     122              : 
     123            4 :   dis->is = is;
     124            4 :   dis->tdh = TALER_MERCHANT_delete_private_template_create (
     125              :     TALER_TESTING_interpreter_get_context (is),
     126              :     dis->merchant_url,
     127              :     dis->template_id);
     128              :   {
     129              :     enum TALER_ErrorCode ec;
     130              : 
     131            4 :     ec = TALER_MERCHANT_delete_private_template_start (dis->tdh,
     132              :                                                        &delete_template_cb,
     133              :                                                        dis);
     134            4 :     GNUNET_assert (TALER_EC_NONE == ec);
     135              :   }
     136            4 : }
     137              : 
     138              : 
     139              : /**
     140              :  * Free the state of a "DELETE template" CMD, and possibly
     141              :  * cancel a pending operation thereof.
     142              :  *
     143              :  * @param cls closure.
     144              :  * @param cmd command being run.
     145              :  */
     146              : static void
     147            4 : delete_template_cleanup (void *cls,
     148              :                          const struct TALER_TESTING_Command *cmd)
     149              : {
     150            4 :   struct DeleteTemplateState *dis = cls;
     151              : 
     152            4 :   if (NULL != dis->tdh)
     153              :   {
     154            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     155              :                 "DELETE /templates/$ID operation did not complete\n");
     156            0 :     TALER_MERCHANT_delete_private_template_cancel (dis->tdh);
     157              :   }
     158            4 :   GNUNET_free (dis);
     159            4 : }
     160              : 
     161              : 
     162              : struct TALER_TESTING_Command
     163            4 : TALER_TESTING_cmd_merchant_delete_template (const char *label,
     164              :                                             const char *merchant_url,
     165              :                                             const char *template_id,
     166              :                                             unsigned int http_status)
     167              : {
     168              :   struct DeleteTemplateState *dis;
     169              : 
     170            4 :   dis = GNUNET_new (struct DeleteTemplateState);
     171            4 :   dis->merchant_url = merchant_url;
     172            4 :   dis->template_id = template_id;
     173            4 :   dis->http_status = http_status;
     174              :   {
     175            4 :     struct TALER_TESTING_Command cmd = {
     176              :       .cls = dis,
     177              :       .label = label,
     178              :       .run = &delete_template_run,
     179              :       .cleanup = &delete_template_cleanup
     180              :     };
     181              : 
     182            4 :     return cmd;
     183              :   }
     184              : }
     185              : 
     186              : 
     187              : /* end of testing_api_cmd_delete_template.c */
        

Generated by: LCOV version 2.0-1