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

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2020 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_instance.c
      21              :  * @brief command to test DELETE /instance/$ID
      22              :  * @author Christian Grothoff
      23              :  */
      24              : #include "platform.h"
      25              : struct DeleteInstanceState;
      26              : #define TALER_MERCHANT_DELETE_MANAGEMENT_INSTANCE_RESULT_CLOSURE struct DeleteInstanceState
      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-management-instances-INSTANCE.h>
      32              : 
      33              : 
      34              : /**
      35              :  * State of a "DELETE /instances/$ID" CMD.
      36              :  */
      37              : struct DeleteInstanceState
      38              : {
      39              : 
      40              :   /**
      41              :    * Handle for a "DELETE instance" request.
      42              :    */
      43              :   struct TALER_MERCHANT_DeleteManagementInstanceHandle *igh;
      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 instance to run DELETE for.
      57              :    */
      58              :   const char *instance_id;
      59              : 
      60              :   /**
      61              :    * Expected HTTP response code.
      62              :    */
      63              :   unsigned int http_status;
      64              : 
      65              :   /**
      66              :    * Use purge, not delete.
      67              :    */
      68              :   bool purge;
      69              : 
      70              : };
      71              : 
      72              : 
      73              : /**
      74              :  * Callback for a /delete/instances/$ID operation.
      75              :  *
      76              :  * @param cls closure for this function
      77              :  * @param dir response being processed
      78              :  */
      79              : static void
      80           18 : delete_instance_cb (struct DeleteInstanceState *dis,
      81              :                     const struct
      82              :                     TALER_MERCHANT_DeleteManagementInstanceResponse *dir)
      83              : {
      84              : 
      85           18 :   dis->igh = NULL;
      86           18 :   if (dis->http_status != dir->hr.http_status)
      87              :   {
      88            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      89              :                 "Unexpected response code %u (%d) to command %s\n",
      90              :                 dir->hr.http_status,
      91              :                 (int) dir->hr.ec,
      92              :                 TALER_TESTING_interpreter_get_current_label (dis->is));
      93            0 :     TALER_TESTING_interpreter_fail (dis->is);
      94            0 :     return;
      95              :   }
      96           18 :   switch (dir->hr.http_status)
      97              :   {
      98           14 :   case MHD_HTTP_NO_CONTENT:
      99           14 :     break;
     100            2 :   case MHD_HTTP_UNAUTHORIZED:
     101            2 :     break;
     102            2 :   case MHD_HTTP_NOT_FOUND:
     103            2 :     break;
     104            0 :   default:
     105            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     106              :                 "Unhandled HTTP status %d for DELETE instance.\n",
     107              :                 dir->hr.http_status);
     108              :   }
     109           18 :   TALER_TESTING_interpreter_next (dis->is);
     110              : }
     111              : 
     112              : 
     113              : /**
     114              :  * Run the "DELETE instance" CMD.
     115              :  *
     116              :  * @param cls closure.
     117              :  * @param cmd command being run now.
     118              :  * @param is interpreter state.
     119              :  */
     120              : static void
     121           18 : delete_instance_run (void *cls,
     122              :                      const struct TALER_TESTING_Command *cmd,
     123              :                      struct TALER_TESTING_Interpreter *is)
     124              : {
     125           18 :   struct DeleteInstanceState *dis = cls;
     126              : 
     127           18 :   dis->is = is;
     128           18 :   dis->igh = TALER_MERCHANT_delete_management_instance_create (
     129              :     TALER_TESTING_interpreter_get_context (is),
     130              :     dis->merchant_url,
     131              :     dis->instance_id);
     132           18 :   if (dis->purge)
     133           14 :     TALER_MERCHANT_delete_management_instance_set_options (
     134              :       dis->igh,
     135              :       { .option = TALER_MERCHANT_DELETE_MANAGEMENT_INSTANCE_OPTION_PURGE });
     136              :   {
     137              :     enum TALER_ErrorCode ec;
     138              : 
     139           18 :     ec = TALER_MERCHANT_delete_management_instance_start (dis->igh,
     140              :                                                           &delete_instance_cb,
     141              :                                                           dis);
     142           18 :     GNUNET_assert (TALER_EC_NONE == ec);
     143              :   }
     144           18 : }
     145              : 
     146              : 
     147              : /**
     148              :  * Free the state of a "DELETE instance" CMD, and possibly
     149              :  * cancel a pending operation thereof.
     150              :  *
     151              :  * @param cls closure.
     152              :  * @param cmd command being run.
     153              :  */
     154              : static void
     155           18 : delete_instance_cleanup (void *cls,
     156              :                          const struct TALER_TESTING_Command *cmd)
     157              : {
     158           18 :   struct DeleteInstanceState *dis = cls;
     159              : 
     160           18 :   if (NULL != dis->igh)
     161              :   {
     162            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     163              :                 "DELETE /instances/$ID operation did not complete\n");
     164            0 :     TALER_MERCHANT_delete_management_instance_cancel (dis->igh);
     165              :   }
     166           18 :   GNUNET_free (dis);
     167           18 : }
     168              : 
     169              : 
     170              : struct TALER_TESTING_Command
     171            4 : TALER_TESTING_cmd_merchant_delete_instance (const char *label,
     172              :                                             const char *merchant_url,
     173              :                                             const char *instance_id,
     174              :                                             unsigned int http_status)
     175              : {
     176              :   struct DeleteInstanceState *dis;
     177              : 
     178            4 :   dis = GNUNET_new (struct DeleteInstanceState);
     179            4 :   dis->merchant_url = merchant_url;
     180            4 :   dis->instance_id = instance_id;
     181            4 :   dis->http_status = http_status;
     182              :   {
     183            4 :     struct TALER_TESTING_Command cmd = {
     184              :       .cls = dis,
     185              :       .label = label,
     186              :       .run = &delete_instance_run,
     187              :       .cleanup = &delete_instance_cleanup
     188              :     };
     189              : 
     190            4 :     return cmd;
     191              :   }
     192              : }
     193              : 
     194              : 
     195              : struct TALER_TESTING_Command
     196           14 : TALER_TESTING_cmd_merchant_purge_instance (const char *label,
     197              :                                            const char *merchant_url,
     198              :                                            const char *instance_id,
     199              :                                            unsigned int http_status)
     200              : {
     201              :   struct DeleteInstanceState *dis;
     202              : 
     203           14 :   dis = GNUNET_new (struct DeleteInstanceState);
     204           14 :   dis->merchant_url = merchant_url;
     205           14 :   dis->instance_id = instance_id;
     206           14 :   dis->http_status = http_status;
     207           14 :   dis->purge = true;
     208              :   {
     209           14 :     struct TALER_TESTING_Command cmd = {
     210              :       .cls = dis,
     211              :       .label = label,
     212              :       .run = &delete_instance_run,
     213              :       .cleanup = &delete_instance_cleanup
     214              :     };
     215              : 
     216           14 :     return cmd;
     217              :   }
     218              : }
     219              : 
     220              : 
     221              : /* end of testing_api_cmd_delete_instance.c */
        

Generated by: LCOV version 2.0-1