LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_instance.c (source / functions) Hit Total Coverage
Test: GNU Taler coverage report Lines: 0 43 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_instance.c
      21             :  * @brief command to test DELETE /instance/$ID
      22             :  * @author Christian Grothoff
      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 /instances/$ID" CMD.
      33             :  */
      34             : struct DeleteInstanceState
      35             : {
      36             : 
      37             :   /**
      38             :    * Handle for a "DELETE instance" request.
      39             :    */
      40             :   struct TALER_MERCHANT_InstanceDeleteHandle *igh;
      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             :    * ID of the instance to run DELETE for.
      54             :    */
      55             :   const char *instance_id;
      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/instances/$ID operation.
      72             :  *
      73             :  * @param cls closure for this function
      74             :  */
      75             : static void
      76           0 : delete_instance_cb (void *cls,
      77             :                     const struct TALER_MERCHANT_HttpResponse *hr)
      78             : {
      79           0 :   struct DeleteInstanceState *dis = cls;
      80             : 
      81           0 :   dis->igh = NULL;
      82           0 :   if (dis->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 (dis->is));
      89           0 :     TALER_TESTING_interpreter_fail (dis->is);
      90           0 :     return;
      91             :   }
      92           0 :   switch (hr->http_status)
      93             :   {
      94           0 :   case MHD_HTTP_OK:
      95           0 :     break;
      96           0 :   default:
      97           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
      98             :                 "Unhandled HTTP status.\n");
      99             :   }
     100           0 :   TALER_TESTING_interpreter_next (dis->is);
     101             : }
     102             : 
     103             : 
     104             : /**
     105             :  * Run the "DELETE instance" CMD.
     106             :  *
     107             :  *
     108             :  * @param cls closure.
     109             :  * @param cmd command being run now.
     110             :  * @param is interpreter state.
     111             :  */
     112             : static void
     113           0 : delete_instance_run (void *cls,
     114             :                      const struct TALER_TESTING_Command *cmd,
     115             :                      struct TALER_TESTING_Interpreter *is)
     116             : {
     117           0 :   struct DeleteInstanceState *dis = cls;
     118             : 
     119           0 :   dis->is = is;
     120           0 :   if (dis->purge)
     121           0 :     dis->igh = TALER_MERCHANT_instance_purge (is->ctx,
     122             :                                               dis->merchant_url,
     123             :                                               dis->instance_id,
     124             :                                               &delete_instance_cb,
     125             :                                               dis);
     126             :   else
     127           0 :     dis->igh = TALER_MERCHANT_instance_delete (is->ctx,
     128             :                                                dis->merchant_url,
     129             :                                                dis->instance_id,
     130             :                                                &delete_instance_cb,
     131             :                                                dis);
     132           0 :   GNUNET_assert (NULL != dis->igh);
     133           0 : }
     134             : 
     135             : 
     136             : /**
     137             :  * Free the state of a "DELETE instance" CMD, and possibly
     138             :  * cancel a pending operation thereof.
     139             :  *
     140             :  * @param cls closure.
     141             :  * @param cmd command being run.
     142             :  */
     143             : static void
     144           0 : delete_instance_cleanup (void *cls,
     145             :                          const struct TALER_TESTING_Command *cmd)
     146             : {
     147           0 :   struct DeleteInstanceState *dis = cls;
     148             : 
     149           0 :   if (NULL != dis->igh)
     150             :   {
     151           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     152             :                 "DELETE /instances/$ID operation did not complete\n");
     153           0 :     TALER_MERCHANT_instance_delete_cancel (dis->igh);
     154             :   }
     155           0 :   GNUNET_free (dis);
     156           0 : }
     157             : 
     158             : 
     159             : /**
     160             :  * Define a "DELETE instance" CMD.
     161             :  *
     162             :  * @param label command label.
     163             :  * @param merchant_url base URL of the merchant serving the
     164             :  *        DELETE /instances/$ID request.
     165             :  * @param instance_id the ID of the instance to query
     166             :  * @param http_status expected HTTP response code.
     167             :  * @return the command.
     168             :  */
     169             : struct TALER_TESTING_Command
     170           0 : TALER_TESTING_cmd_merchant_delete_instance (const char *label,
     171             :                                             const char *merchant_url,
     172             :                                             const char *instance_id,
     173             :                                             unsigned int http_status)
     174             : {
     175             :   struct DeleteInstanceState *dis;
     176             : 
     177           0 :   dis = GNUNET_new (struct DeleteInstanceState);
     178           0 :   dis->merchant_url = merchant_url;
     179           0 :   dis->instance_id = instance_id;
     180           0 :   dis->http_status = http_status;
     181             :   {
     182           0 :     struct TALER_TESTING_Command cmd = {
     183             :       .cls = dis,
     184             :       .label = label,
     185             :       .run = &delete_instance_run,
     186             :       .cleanup = &delete_instance_cleanup
     187             :     };
     188             : 
     189           0 :     return cmd;
     190             :   }
     191             : }
     192             : 
     193             : 
     194             : /**
     195             :  * Define a "PURGE instance" CMD.
     196             :  *
     197             :  * @param label command label.
     198             :  * @param merchant_url base URL of the merchant serving the
     199             :  *        PURGE /instances/$ID request.
     200             :  * @param instance_id the ID of the instance to query
     201             :  * @param http_status expected HTTP response code.
     202             :  * @return the command.
     203             :  */
     204             : struct TALER_TESTING_Command
     205           0 : TALER_TESTING_cmd_merchant_purge_instance (const char *label,
     206             :                                            const char *merchant_url,
     207             :                                            const char *instance_id,
     208             :                                            unsigned int http_status)
     209             : {
     210             :   struct DeleteInstanceState *dis;
     211             : 
     212           0 :   dis = GNUNET_new (struct DeleteInstanceState);
     213           0 :   dis->merchant_url = merchant_url;
     214           0 :   dis->instance_id = instance_id;
     215           0 :   dis->http_status = http_status;
     216           0 :   dis->purge = true;
     217             :   {
     218           0 :     struct TALER_TESTING_Command cmd = {
     219             :       .cls = dis,
     220             :       .label = label,
     221             :       .run = &delete_instance_run,
     222             :       .cleanup = &delete_instance_cleanup
     223             :     };
     224             : 
     225           0 :     return cmd;
     226             :   }
     227             : }
     228             : 
     229             : 
     230             : /* end of testing_api_cmd_delete_instance.c */

Generated by: LCOV version 1.14