merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_get_donau_instances.c (4900B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2021 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 testing_api_cmd_kyc_get.c
     21  * @brief command to test kyc_get request
     22  * @author Bohdan Potuzhnyi
     23  * @author Vlada Svirsh
     24  */
     25 #include "platform.h"
     26 #include <taler/taler_exchange_service.h>
     27 #include <taler/taler_testing_lib.h>
     28 #include "taler_merchant_service.h"
     29 #include "taler_merchant_testing_lib.h"
     30 #include "taler_merchant_donau.h"
     31 
     32 /**
     33  * State of a "GET donau instances" CMD.
     34  */
     35 struct GetDonauInstancesState
     36 {
     37   /**
     38    * Handle for a "GET donau instances" request.
     39    */
     40   struct TALER_MERCHANT_DonauInstanceGetHandle *dgh;
     41 
     42   /**
     43    * The interpreter state.
     44    */
     45   struct TALER_TESTING_Interpreter *is;
     46 
     47   /**
     48    * Base URL of the merchant/donau service.
     49    */
     50   const char *url;
     51 
     52   /**
     53    * Expected HTTP response code.
     54    */
     55   unsigned int expected_http_status;
     56 
     57   /**
     58    * The number of instances in the `instances` array.
     59    */
     60   unsigned int instances_length;
     61 };
     62 
     63 /**
     64  * Callback for a /get/donau operation.
     65  *
     66  * @param cls closure for this function
     67  * @param response response details from the Donau service
     68  */
     69 static void
     70 get_donau_instances_cb (void *cls,
     71                         const struct
     72                         TALER_MERCHANT_DonauInstanceGetResponse *response)
     73 {
     74   struct GetDonauInstancesState *gis = cls;
     75 
     76   gis->dgh = NULL;
     77 
     78   if (gis->expected_http_status != response->hr.http_status)
     79   {
     80     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     81                 "Unexpected response code %u (%d) to command %s\n",
     82                 response->hr.http_status,
     83                 (int) response->hr.ec,
     84                 TALER_TESTING_interpreter_get_current_label (gis->is));
     85     TALER_TESTING_interpreter_fail (gis->is);
     86     return;
     87   }
     88 
     89   if (MHD_HTTP_OK == response->hr.http_status)
     90   {
     91     unsigned int instance_count = response->details.ok.donau_instances_length;
     92     if (instance_count != gis->instances_length)
     93     {
     94       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     95                   "Expected %u instances, but got %u\n",
     96                   gis->instances_length, instance_count);
     97       TALER_TESTING_interpreter_fail (gis->is);
     98       return;
     99     }
    100   }
    101   TALER_TESTING_interpreter_next (gis->is);
    102 }
    103 
    104 
    105 /**
    106  * Run the "GET donau instance" CMD.
    107  *
    108  * @param cls closure.
    109  * @param cmd command being run now.
    110  * @param is interpreter state.
    111  */
    112 static void
    113 get_donau_instances_run (void *cls,
    114                          const struct TALER_TESTING_Command *cmd,
    115                          struct TALER_TESTING_Interpreter *is)
    116 {
    117   struct GetDonauInstancesState *gis = cls;
    118 
    119   gis->is = is;
    120   gis->dgh = TALER_MERCHANT_donau_instances_get (
    121     TALER_TESTING_interpreter_get_context (is),
    122     gis->url,
    123     &get_donau_instances_cb,
    124     gis);
    125 
    126   GNUNET_assert (NULL != gis->dgh);
    127 }
    128 
    129 
    130 /**
    131  * Free the state of a "GET donau instance" CMD, and possibly
    132  * cancel a pending operation thereof.
    133  *
    134  * @param cls closure.
    135  * @param cmd command being run.
    136  */
    137 static void
    138 get_donau_instances_cleanup (void *cls,
    139                              const struct TALER_TESTING_Command *cmd)
    140 {
    141   struct GetDonauInstancesState *gis = cls;
    142 
    143   if (NULL != gis->dgh)
    144   {
    145     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
    146                 "GET /donau instances operation did not complete\n");
    147     TALER_MERCHANT_donau_instances_get_cancel (gis->dgh);
    148   }
    149 
    150   GNUNET_free (gis);
    151 }
    152 
    153 
    154 /**
    155  * Creation of the "GET donau instances" CMD.
    156  */
    157 struct TALER_TESTING_Command
    158 TALER_TESTING_cmd_merchant_get_donau_instances (const char *label,
    159                                                 const char *url,
    160                                                 unsigned int instance_count,
    161                                                 unsigned int
    162                                                 expected_http_status,
    163                                                 ...)
    164 {
    165   struct GetDonauInstancesState *gis;
    166   va_list ap;
    167 
    168   gis = GNUNET_new (struct GetDonauInstancesState);
    169   gis->url = url;
    170   gis->expected_http_status = expected_http_status;
    171   gis->instances_length = instance_count;
    172 
    173   va_start (ap, expected_http_status);
    174   va_end (ap);
    175   {
    176     struct TALER_TESTING_Command cmd = {
    177       .cls = gis,
    178       .label = label,
    179       .run = &get_donau_instances_run,
    180       .cleanup = &get_donau_instances_cleanup
    181     };
    182     return cmd;
    183   }
    184 }