LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_reserve.c (source / functions) Hit Total Coverage
Test: GNU Taler coverage report Lines: 0 50 0.0 %
Date: 2020-08-15 06:12:35 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          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 lib/testing_api_cmd_delete_reserve.c
      21             :  * @brief command to test DELETE /reserves/$RESERVE_PUB
      22             :  * @author Jonathan Buchanan
      23             :  */
      24             : #include "platform.h"
      25             : #include <taler/taler_exchange_service.h>
      26             : #include <taler/taler_testing_lib.h>
      27             : #include "taler_merchant_service.h"
      28             : #include "taler_merchant_testing_lib.h"
      29             : 
      30             : 
      31             : /**
      32             :  * State of a "DELETE /reserves/$RESERVE_PUB" CMD.
      33             :  */
      34             : struct DeleteReserveState
      35             : {
      36             : 
      37             :   /**
      38             :    * Handle for a "DELETE reserve" request.
      39             :    */
      40             :   struct TALER_MERCHANT_ReserveDeleteHandle *rdh;
      41             : 
      42             :   /**
      43             :    * The interpreter state.
      44             :    */
      45             :   struct TALER_TESTING_Interpreter *is;
      46             : 
      47             :   /**
      48             :    * Base URL of the merchant serving the request.
      49             :    */
      50             :   const char *merchant_url;
      51             : 
      52             :   /**
      53             :    * Reference to a command that provides a reserve.
      54             :    */
      55             :   const char *reserve_reference;
      56             : 
      57             :   /**
      58             :    * Expected HTTP response code.
      59             :    */
      60             :   unsigned int http_status;
      61             : 
      62             :   /**
      63             :    * Use purge, not delete.
      64             :    */
      65             :   bool purge;
      66             : 
      67             : };
      68             : 
      69             : 
      70             : /**
      71             :  * Callback for a DELETE /reserves/$RESERVE_PUB operation.
      72             :  *
      73             :  * @param cls closure for this function
      74             :  */
      75             : static void
      76           0 : delete_reserve_cb (void *cls,
      77             :                    const struct TALER_MERCHANT_HttpResponse *hr)
      78             : {
      79           0 :   struct DeleteReserveState *drs = cls;
      80             : 
      81           0 :   drs->rdh = NULL;
      82           0 :   if (drs->http_status != hr->http_status)
      83             :   {
      84           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      85             :                 "Unexpected response code %u (%d) to command %s\n",
      86             :                 hr->http_status,
      87             :                 (int) hr->ec,
      88             :                 TALER_TESTING_interpreter_get_current_label (drs->is));
      89           0 :     TALER_TESTING_interpreter_fail (drs->is);
      90           0 :     return;
      91             :   }
      92           0 :   switch (hr->http_status)
      93             :   {
      94           0 :   case MHD_HTTP_NO_CONTENT:
      95           0 :     break;
      96           0 :   case MHD_HTTP_NOT_FOUND:
      97           0 :     break;
      98           0 :   case MHD_HTTP_CONFLICT:
      99           0 :     break;
     100           0 :   default:
     101           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     102             :                 "Unhandled HTTP status.\n");
     103             :   }
     104           0 :   TALER_TESTING_interpreter_next (drs->is);
     105             : }
     106             : 
     107             : 
     108             : /**
     109             :  * Run the "DELETE reserve" CMD.
     110             :  *
     111             :  * @param cls closure.
     112             :  * @param cmd command being run now.
     113             :  * @param is interpreter state.
     114             :  */
     115             : static void
     116           0 : delete_reserve_run (void *cls,
     117             :                     const struct TALER_TESTING_Command *cmd,
     118             :                     struct TALER_TESTING_Interpreter *is)
     119             : {
     120           0 :   struct DeleteReserveState *drs = cls;
     121             :   const struct TALER_TESTING_Command *reserve_cmd;
     122             :   const struct TALER_ReservePublicKeyP *reserve_pub;
     123             : 
     124           0 :   reserve_cmd = TALER_TESTING_interpreter_lookup_command (
     125             :     is,
     126             :     drs->reserve_reference);
     127           0 :   if (GNUNET_OK !=
     128           0 :       TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
     129             :                                            0,
     130             :                                            &reserve_pub))
     131           0 :     TALER_TESTING_FAIL (is);
     132             : 
     133           0 :   drs->is = is;
     134           0 :   if (drs->purge)
     135           0 :     drs->rdh = TALER_MERCHANT_reserve_purge (is->ctx,
     136             :                                              drs->merchant_url,
     137             :                                              reserve_pub,
     138             :                                              &delete_reserve_cb,
     139             :                                              drs);
     140             :   else
     141           0 :     drs->rdh = TALER_MERCHANT_reserve_delete (is->ctx,
     142             :                                               drs->merchant_url,
     143             :                                               reserve_pub,
     144             :                                               &delete_reserve_cb,
     145             :                                               drs);
     146             : 
     147           0 :   GNUNET_assert (NULL != drs->rdh);
     148             : }
     149             : 
     150             : 
     151             : /**
     152             :  * Free the state of a "DELETE reserve" CMD, and possibly
     153             :  * cancel a pending operation thereof.
     154             :  *
     155             :  * @param cls closure.
     156             :  * @param cmd command being run.
     157             :  */
     158             : static void
     159           0 : delete_reserve_cleanup (void *cls,
     160             :                         const struct TALER_TESTING_Command *cmd)
     161             : {
     162           0 :   struct DeleteReserveState *drs = cls;
     163             : 
     164           0 :   if (NULL != drs->rdh)
     165             :   {
     166           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     167             :                 "DELETE /reserves/$RESERVE_PUB operation did not complete\n");
     168           0 :     TALER_MERCHANT_reserve_delete_cancel (drs->rdh);
     169             :   }
     170           0 :   GNUNET_free (drs);
     171           0 : }
     172             : 
     173             : 
     174             : /**
     175             :  * Define a "DELETE reserve" CMD.
     176             :  *
     177             :  * @param label command label.
     178             :  * @param merchant_url base URL of the merchant serving the
     179             :  *        DELETE /reserves/$RESERVE_PUB request.
     180             :  * @param reserve_reference command label of a command providing a reserve
     181             :  * @param http_status expected HTTP response code.
     182             :  * @return the command.
     183             :  */
     184             : struct TALER_TESTING_Command
     185           0 : TALER_TESTING_cmd_merchant_delete_reserve (const char *label,
     186             :                                            const char *merchant_url,
     187             :                                            const char *reserve_reference,
     188             :                                            unsigned int http_status)
     189             : {
     190             :   struct DeleteReserveState *drs;
     191             : 
     192           0 :   drs = GNUNET_new (struct DeleteReserveState);
     193           0 :   drs->merchant_url = merchant_url;
     194           0 :   drs->reserve_reference = reserve_reference;
     195           0 :   drs->http_status = http_status;
     196             :   {
     197           0 :     struct TALER_TESTING_Command cmd = {
     198             :       .cls = drs,
     199             :       .label = label,
     200             :       .run = &delete_reserve_run,
     201             :       .cleanup = &delete_reserve_cleanup
     202             :     };
     203             : 
     204           0 :     return cmd;
     205             :   }
     206             : }
     207             : 
     208             : 
     209             : /**
     210             :  * Define a "PURGE reserve" CMD.
     211             :  *
     212             :  * @param label command label.
     213             :  * @param merchant_url base URL of the merchant serving the
     214             :  *        DELETE /reserves/$RESERVE_PUB request.
     215             :  * @param reserve_reference command label of a command providing a reserve
     216             :  * @param http_status expected HTTP response code.
     217             :  * @return the command.
     218             :  */
     219             : struct TALER_TESTING_Command
     220           0 : TALER_TESTING_cmd_merchant_purge_reserve (const char *label,
     221             :                                           const char *merchant_url,
     222             :                                           const char *reserve_reference,
     223             :                                           unsigned int http_status)
     224             : {
     225             :   struct DeleteReserveState *drs;
     226             : 
     227           0 :   drs = GNUNET_new (struct DeleteReserveState);
     228           0 :   drs->merchant_url = merchant_url;
     229           0 :   drs->reserve_reference = reserve_reference;
     230           0 :   drs->http_status = http_status;
     231           0 :   drs->purge = true;
     232             :   {
     233           0 :     struct TALER_TESTING_Command cmd = {
     234             :       .cls = drs,
     235             :       .label = label,
     236             :       .run = &delete_reserve_run,
     237             :       .cleanup = &delete_reserve_cleanup
     238             :     };
     239             : 
     240           0 :     return cmd;
     241             :   }
     242             : }
     243             : 
     244             : 
     245             : /* end of testing_api_cmd_delete_reserve.c */

Generated by: LCOV version 1.14