LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_product.c (source / functions) Hit Total Coverage
Test: GNU Taler coverage report Lines: 0 33 0.0 %
Date: 2020-08-15 06:12:35 Functions: 0 4 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_product.c
      21             :  * @brief command to test DELETE /product/$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 /products/$ID" CMD.
      33             :  */
      34             : struct DeleteProductState
      35             : {
      36             : 
      37             :   /**
      38             :    * Handle for a "DELETE product" request.
      39             :    */
      40             :   struct TALER_MERCHANT_ProductDeleteHandle *pdh;
      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 product to run DELETE for.
      54             :    */
      55             :   const char *product_id;
      56             : 
      57             :   /**
      58             :    * Expected HTTP response code.
      59             :    */
      60             :   unsigned int http_status;
      61             : 
      62             : };
      63             : 
      64             : 
      65             : /**
      66             :  * Callback for a /delete/products/$ID operation.
      67             :  *
      68             :  * @param cls closure for this function
      69             :  */
      70             : static void
      71           0 : delete_product_cb (void *cls,
      72             :                    const struct TALER_MERCHANT_HttpResponse *hr)
      73             : {
      74           0 :   struct DeleteProductState *dis = cls;
      75             : 
      76           0 :   dis->pdh = NULL;
      77           0 :   if (dis->http_status != hr->http_status)
      78             :   {
      79           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      80             :                 "Unexpected response code %u (%d) to command %s\n",
      81             :                 hr->http_status,
      82             :                 (int) hr->ec,
      83             :                 TALER_TESTING_interpreter_get_current_label (dis->is));
      84           0 :     TALER_TESTING_interpreter_fail (dis->is);
      85           0 :     return;
      86             :   }
      87           0 :   switch (hr->http_status)
      88             :   {
      89           0 :   case MHD_HTTP_OK:
      90           0 :     break;
      91           0 :   default:
      92           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
      93             :                 "Unhandled HTTP status.\n");
      94             :   }
      95           0 :   TALER_TESTING_interpreter_next (dis->is);
      96             : }
      97             : 
      98             : 
      99             : /**
     100             :  * Run the "DELETE product" CMD.
     101             :  *
     102             :  *
     103             :  * @param cls closure.
     104             :  * @param cmd command being run now.
     105             :  * @param is interpreter state.
     106             :  */
     107             : static void
     108           0 : delete_product_run (void *cls,
     109             :                     const struct TALER_TESTING_Command *cmd,
     110             :                     struct TALER_TESTING_Interpreter *is)
     111             : {
     112           0 :   struct DeleteProductState *dis = cls;
     113             : 
     114           0 :   dis->is = is;
     115           0 :   dis->pdh = TALER_MERCHANT_product_delete (is->ctx,
     116             :                                             dis->merchant_url,
     117             :                                             dis->product_id,
     118             :                                             &delete_product_cb,
     119             :                                             dis);
     120           0 :   GNUNET_assert (NULL != dis->pdh);
     121           0 : }
     122             : 
     123             : 
     124             : /**
     125             :  * Free the state of a "DELETE product" CMD, and possibly
     126             :  * cancel a pending operation thereof.
     127             :  *
     128             :  * @param cls closure.
     129             :  * @param cmd command being run.
     130             :  */
     131             : static void
     132           0 : delete_product_cleanup (void *cls,
     133             :                         const struct TALER_TESTING_Command *cmd)
     134             : {
     135           0 :   struct DeleteProductState *dis = cls;
     136             : 
     137           0 :   if (NULL != dis->pdh)
     138             :   {
     139           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     140             :                 "DELETE /products/$ID operation did not complete\n");
     141           0 :     TALER_MERCHANT_product_delete_cancel (dis->pdh);
     142             :   }
     143           0 :   GNUNET_free (dis);
     144           0 : }
     145             : 
     146             : 
     147             : /**
     148             :  * Define a "DELETE product" CMD.
     149             :  *
     150             :  * @param label command label.
     151             :  * @param merchant_url base URL of the merchant serving the
     152             :  *        DELETE /products/$ID request.
     153             :  * @param product_id the ID of the product to query
     154             :  * @param http_status expected HTTP response code.
     155             :  * @return the command.
     156             :  */
     157             : struct TALER_TESTING_Command
     158           0 : TALER_TESTING_cmd_merchant_delete_product (const char *label,
     159             :                                            const char *merchant_url,
     160             :                                            const char *product_id,
     161             :                                            unsigned int http_status)
     162             : {
     163             :   struct DeleteProductState *dis;
     164             : 
     165           0 :   dis = GNUNET_new (struct DeleteProductState);
     166           0 :   dis->merchant_url = merchant_url;
     167           0 :   dis->product_id = product_id;
     168           0 :   dis->http_status = http_status;
     169             :   {
     170           0 :     struct TALER_TESTING_Command cmd = {
     171             :       .cls = dis,
     172             :       .label = label,
     173             :       .run = &delete_product_run,
     174             :       .cleanup = &delete_product_cleanup
     175             :     };
     176             : 
     177           0 :     return cmd;
     178             :   }
     179             : }
     180             : 
     181             : 
     182             : /* end of testing_api_cmd_delete_product.c */

Generated by: LCOV version 1.14