merchant

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

testing_api_cmd_tme.c (4711B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2023 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,
      8   or (at your option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful,
     11   but 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/testing_api_cmd_tme.c
     21  * @brief run the taler-merchant-reconciliation command
     22  * @author Christian Grothoff
     23  */
     24 #include "taler/platform.h"
     25 #include "taler/taler_json_lib.h"
     26 #include <gnunet/gnunet_curl_lib.h>
     27 #include "taler/taler_signatures.h"
     28 #include "taler/taler_testing_lib.h"
     29 #include "taler/taler_merchant_testing_lib.h"
     30 
     31 
     32 /**
     33  * State for a "taler-merchant-reconciliation" CMD.
     34  */
     35 struct MerchantExchangeState
     36 {
     37 
     38   /**
     39    * Process for taler-merchant-reconciliation
     40    */
     41   struct GNUNET_Process *merchant_reconciliation_proc;
     42 
     43   /**
     44    * Configuration file used by the program.
     45    */
     46   const char *config_filename;
     47 };
     48 
     49 
     50 /**
     51  * Run the command; use the `taler-merchant-reconciliation' program.
     52  *
     53  * @param cls closure.
     54  * @param cmd command currently being executed.
     55  * @param is interpreter state.
     56  */
     57 static void
     58 tme_run (void *cls,
     59          const struct TALER_TESTING_Command *cmd,
     60          struct TALER_TESTING_Interpreter *is)
     61 {
     62   struct MerchantExchangeState *ws = cls;
     63 
     64   (void) cmd;
     65   ws->merchant_reconciliation_proc
     66     = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR);
     67   if (GNUNET_OK !=
     68       GNUNET_process_run_command_va (ws->merchant_reconciliation_proc,
     69                                      "taler-merchant-reconciliation",
     70                                      "taler-merchant-reconciliation",
     71                                      "-c", ws->config_filename,
     72                                      "-t",   /* exit when done */
     73                                      "-T", "1200s",
     74                                      "-L", "INFO",
     75                                      NULL))
     76   {
     77     GNUNET_break (0);
     78     GNUNET_process_destroy (ws->merchant_reconciliation_proc);
     79     ws->merchant_reconciliation_proc = NULL;
     80     TALER_TESTING_interpreter_fail (is);
     81     return;
     82   }
     83   TALER_TESTING_wait_for_sigchld (is);
     84 }
     85 
     86 
     87 /**
     88  * Free the state of a "exchange" CMD, and possibly
     89  * kills its process if it did not terminate regularly.
     90  *
     91  * @param cls closure.
     92  * @param cmd the command being freed.
     93  */
     94 static void
     95 tme_cleanup (void *cls,
     96              const struct TALER_TESTING_Command *cmd)
     97 {
     98   struct MerchantExchangeState *ws = cls;
     99 
    100   (void) cmd;
    101   if (NULL != ws->merchant_reconciliation_proc)
    102   {
    103     GNUNET_break (GNUNET_OK ==
    104                   GNUNET_process_kill (ws->merchant_reconciliation_proc,
    105                                        SIGKILL));
    106     GNUNET_break (GNUNET_OK ==
    107                   GNUNET_process_wait (ws->merchant_reconciliation_proc,
    108                                        true,
    109                                        NULL,
    110                                        NULL));
    111     GNUNET_process_destroy (ws->merchant_reconciliation_proc);
    112     ws->merchant_reconciliation_proc = NULL;
    113   }
    114   GNUNET_free (ws);
    115 }
    116 
    117 
    118 /**
    119  * Offer "tme" CMD internal data to other commands.
    120  *
    121  * @param cls closure.
    122  * @param[out] ret result.
    123  * @param trait name of the trait.
    124  * @param index index number of the object to offer.
    125  * @return #GNUNET_OK on success.
    126  */
    127 static enum GNUNET_GenericReturnValue
    128 tme_traits (void *cls,
    129             const void **ret,
    130             const char *trait,
    131             unsigned int index)
    132 {
    133   struct MerchantExchangeState *ws = cls;
    134   struct TALER_TESTING_Trait traits[] = {
    135     TALER_TESTING_make_trait_process (&ws->merchant_reconciliation_proc),
    136     TALER_TESTING_trait_end ()
    137   };
    138 
    139   return TALER_TESTING_get_trait (traits,
    140                                   ret,
    141                                   trait,
    142                                   index);
    143 }
    144 
    145 
    146 struct TALER_TESTING_Command
    147 TALER_TESTING_cmd_run_tme (const char *label,
    148                            const char *config_filename)
    149 {
    150   struct MerchantExchangeState *ws;
    151 
    152   ws = GNUNET_new (struct MerchantExchangeState);
    153   ws->config_filename = config_filename;
    154 
    155   {
    156     struct TALER_TESTING_Command cmd = {
    157       .cls = ws,
    158       .label = label,
    159       .run = &tme_run,
    160       .cleanup = &tme_cleanup,
    161       .traits = &tme_traits
    162     };
    163 
    164     return cmd;
    165   }
    166 }
    167 
    168 
    169 /* end of testing_api_cmd_tme.c */