testing_api_cmd_get_donau_instances.c (5050B)
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/get-private-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_GetPrivateDonauHandle *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_GetPrivateDonauResponse *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_get_private_donau_create ( 121 TALER_TESTING_interpreter_get_context (is), 122 gis->url); 123 { 124 enum TALER_ErrorCode ec; 125 126 ec = TALER_MERCHANT_get_private_donau_start ( 127 gis->dgh, 128 &get_donau_instances_cb, 129 gis); 130 GNUNET_assert (TALER_EC_NONE == ec); 131 } 132 } 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 get_donau_instances_cleanup (void *cls, 144 const struct TALER_TESTING_Command *cmd) 145 { 146 struct GetDonauInstancesState *gis = cls; 147 148 if (NULL != gis->dgh) 149 { 150 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 151 "GET /donau instances operation did not complete\n"); 152 TALER_MERCHANT_get_private_donau_cancel (gis->dgh); 153 } 154 155 GNUNET_free (gis); 156 } 157 158 159 /** 160 * Creation of the "GET donau instances" CMD. 161 */ 162 struct TALER_TESTING_Command 163 TALER_TESTING_cmd_merchant_get_donau_instances (const char *label, 164 const char *url, 165 unsigned int instance_count, 166 unsigned int 167 expected_http_status, 168 ...) 169 { 170 struct GetDonauInstancesState *gis; 171 va_list ap; 172 173 gis = GNUNET_new (struct GetDonauInstancesState); 174 gis->url = url; 175 gis->expected_http_status = expected_http_status; 176 gis->instances_length = instance_count; 177 178 va_start (ap, expected_http_status); 179 va_end (ap); 180 { 181 struct TALER_TESTING_Command cmd = { 182 .cls = gis, 183 .label = label, 184 .run = &get_donau_instances_run, 185 .cleanup = &get_donau_instances_cleanup 186 }; 187 return cmd; 188 } 189 }