LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_get_donau_instances.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 76.5 % 34 26
Test Date: 2026-09-11 17:45:24 Functions: 100.0 % 4 4

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

Generated by: LCOV version 2.0-1