merchant

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

testing_api_cmd_get_donau_instances.c (5090B)


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