LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_config.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 27 0.0 %
Date: 2022-08-25 06:17:04 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             : /**
      21             :  * @file testing_api_cmd_config.c
      22             :  * @brief command to test config request
      23             :  * @author Christian Grothoff
      24             :  */
      25             : 
      26             : #include "platform.h"
      27             : #include <taler/taler_exchange_service.h>
      28             : #include <taler/taler_testing_lib.h>
      29             : #include "taler_merchant_service.h"
      30             : #include "taler_merchant_testing_lib.h"
      31             : 
      32             : 
      33             : /**
      34             :  * State for a "config" CMD.
      35             :  */
      36             : struct ConfigState
      37             : {
      38             :   /**
      39             :    * Operation handle for a GET /public/config request.
      40             :    */
      41             :   struct TALER_MERCHANT_ConfigGetHandle *vgh;
      42             : 
      43             :   /**
      44             :    * Base URL of the merchant serving the request.
      45             :    */
      46             :   const char *merchant_url;
      47             : 
      48             :   /**
      49             :    * Expected HTTP response code.
      50             :    */
      51             :   unsigned int http_code;
      52             : 
      53             :   /**
      54             :    * Interpreter state.
      55             :    */
      56             :   struct TALER_TESTING_Interpreter *is;
      57             : 
      58             : };
      59             : 
      60             : 
      61             : /**
      62             :  * Free the state of a "config" CMD, and
      63             :  * possibly cancel a pending "config" operation.
      64             :  *
      65             :  * @param cls closure with the `struct ConfigState`
      66             :  * @param cmd command currently being freed.
      67             :  */
      68             : static void
      69           0 : config_cleanup (void *cls,
      70             :                 const struct TALER_TESTING_Command *cmd)
      71             : {
      72           0 :   struct ConfigState *cs = cls;
      73             : 
      74           0 :   if (NULL != cs->vgh)
      75             :   {
      76           0 :     TALER_LOG_WARNING ("config operation did not complete\n");
      77           0 :     TALER_MERCHANT_config_get_cancel (cs->vgh);
      78             :   }
      79           0 :   GNUNET_free (cs);
      80           0 : }
      81             : 
      82             : 
      83             : /**
      84             :  * Process "GET /public/config" (lookup) response.
      85             :  *
      86             :  * @param cls closure
      87             :  * @param hr HTTP response we got
      88             :  * @param ci basic information about the merchant
      89             :  * @param compat protocol compatibility information
      90             :  */
      91             : static void
      92           0 : config_cb (void *cls,
      93             :            const struct TALER_MERCHANT_HttpResponse *hr,
      94             :            const struct TALER_MERCHANT_ConfigInformation *ci,
      95             :            enum TALER_MERCHANT_VersionCompatibility compat)
      96             : {
      97           0 :   struct ConfigState *cs = cls;
      98             : 
      99             :   (void) ci;
     100           0 :   cs->vgh = NULL;
     101           0 :   if (cs->http_code != hr->http_status)
     102           0 :     TALER_TESTING_FAIL (cs->is);
     103           0 :   if (TALER_MERCHANT_VC_MATCH != compat)
     104           0 :     TALER_TESTING_FAIL (cs->is);
     105           0 :   TALER_TESTING_interpreter_next (cs->is);
     106             : }
     107             : 
     108             : 
     109             : /**
     110             :  * Run the "config" CMD.
     111             :  *
     112             :  * @param cls closure.
     113             :  * @param cmd command being currently run.
     114             :  * @param is interpreter state.
     115             :  */
     116             : static void
     117           0 : config_run (void *cls,
     118             :             const struct TALER_TESTING_Command *cmd,
     119             :             struct TALER_TESTING_Interpreter *is)
     120             : {
     121           0 :   struct ConfigState *cs = cls;
     122             : 
     123           0 :   cs->is = is;
     124           0 :   cs->vgh = TALER_MERCHANT_config_get (is->ctx,
     125             :                                        cs->merchant_url,
     126             :                                        &config_cb,
     127             :                                        cs);
     128           0 :   GNUNET_assert (NULL != cs->vgh);
     129           0 : }
     130             : 
     131             : 
     132             : struct TALER_TESTING_Command
     133           0 : TALER_TESTING_cmd_config (const char *label,
     134             :                           const char *merchant_url,
     135             :                           unsigned int http_code)
     136             : {
     137             :   struct ConfigState *cs;
     138             : 
     139           0 :   cs = GNUNET_new (struct ConfigState);
     140           0 :   cs->merchant_url = merchant_url;
     141           0 :   cs->http_code = http_code;
     142             :   {
     143           0 :     struct TALER_TESTING_Command cmd = {
     144             :       .cls = cs,
     145             :       .label = label,
     146             :       .run = &config_run,
     147             :       .cleanup = &config_cleanup
     148             :     };
     149             : 
     150           0 :     return cmd;
     151             :   }
     152             : }
     153             : 
     154             : 
     155             : /* end of testing_api_cmd_config.c */

Generated by: LCOV version 1.14