testing_api_cmd_delete_donau_instances.c (4774B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Lesser General Public License as published by the Free Software 7 Foundation; either version 2.1, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 12 13 You should have received a copy of the GNU Lesser General Public License along with TALER; 14 see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file testing_api_cmd_delete_donau_instances.c 18 * @brief Command to test DELETE /donau/$charity_id request 19 * @author Bohdan Potuzhnyi 20 * @author Vlada Svirsh 21 */ 22 23 #include "platform.h" 24 #include <taler/taler_testing_lib.h> 25 #include "taler_merchant_service.h" 26 #include "taler_merchant_testing_lib.h" 27 #include "taler_merchant_donau.h" 28 29 /** 30 * State for DELETE /donau/$charity_id testing command. 31 */ 32 struct DeleteDonauState 33 { 34 /** 35 * Handle for a DELETE /donau request. 36 */ 37 struct TALER_MERCHANT_DonauInstanceDeleteHandle *ddh; 38 39 /** 40 * The interpreter state. 41 */ 42 struct TALER_TESTING_Interpreter *is; 43 44 /** 45 * Base URL of the Donau service. 46 */ 47 const char *url; 48 49 /** 50 * Charity ID to delete. 51 */ 52 uint64_t charity_id; 53 54 /** 55 * Expected HTTP response code. 56 */ 57 unsigned int expected_http_status; 58 }; 59 60 /** 61 * Callback for DELETE /donau/$charity_id operation. 62 * 63 * @param cls closure for this function 64 * @param hr HTTP response details 65 */ 66 static void 67 delete_donau_cb (void *cls, 68 const struct TALER_MERCHANT_HttpResponse *hr) 69 { 70 struct DeleteDonauState *dds = cls; 71 72 dds->ddh = NULL; 73 74 if (dds->expected_http_status != hr->http_status) 75 { 76 TALER_TESTING_unexpected_status_with_body ( 77 dds->is, 78 hr->http_status, 79 dds->expected_http_status, 80 hr->reply); 81 TALER_TESTING_interpreter_fail (dds->is); 82 return; 83 } 84 85 switch (hr->http_status) 86 { 87 case MHD_HTTP_NO_CONTENT: 88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 89 "DELETE /donau succeeded\n"); 90 break; 91 case MHD_HTTP_NOT_FOUND: 92 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 93 "DELETE /donau: Charity not found\n"); 94 break; 95 case MHD_HTTP_UNAUTHORIZED: 96 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 97 "DELETE /donau: Unauthorized access\n"); 98 break; 99 default: 100 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 101 "Unhandled HTTP status %u\n", 102 hr->http_status); 103 } 104 105 TALER_TESTING_interpreter_next (dds->is); 106 } 107 108 109 /** 110 * Run the DELETE /donau/$charity_id test command. 111 * 112 * @param cls closure. 113 * @param cmd command being run now. 114 * @param is interpreter state. 115 */ 116 static void 117 delete_donau_run (void *cls, 118 const struct TALER_TESTING_Command *cmd, 119 struct TALER_TESTING_Interpreter *is) 120 { 121 struct DeleteDonauState *dds = cls; 122 123 dds->is = is; 124 dds->ddh = TALER_MERCHANT_donau_instance_delete ( 125 TALER_TESTING_interpreter_get_context (is), 126 dds->url, 127 dds->charity_id, 128 &delete_donau_cb, 129 dds); 130 131 if (NULL == dds->ddh) 132 { 133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 134 "Failed to initiate DELETE /donau/$charity_id\n"); 135 TALER_TESTING_interpreter_fail (is); 136 return; 137 } 138 } 139 140 141 /** 142 * Clean up state for DELETE /donau/$charity_id command. 143 * 144 * @param cls closure. 145 * @param cmd command being run. 146 */ 147 static void 148 delete_donau_cleanup (void *cls, 149 const struct TALER_TESTING_Command *cmd) 150 { 151 struct DeleteDonauState *dds = cls; 152 153 if (NULL != dds->ddh) 154 { 155 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 156 "DELETE /donau/$charity_id operation did not complete\n"); 157 TALER_MERCHANT_donau_instance_delete_cancel (dds->ddh); 158 } 159 GNUNET_free (dds); 160 } 161 162 163 /** 164 * Create a DELETE /donau/$charity_id testing command. 165 */ 166 struct TALER_TESTING_Command 167 TALER_TESTING_cmd_merchant_delete_donau_instance (const char *label, 168 const char *url, 169 uint64_t charity_id, 170 unsigned int 171 expected_http_status) 172 { 173 struct DeleteDonauState *dds = GNUNET_new (struct DeleteDonauState); 174 175 dds->url = url; 176 dds->charity_id = charity_id; 177 dds->expected_http_status = expected_http_status; 178 179 { 180 struct TALER_TESTING_Command cmd = { 181 .cls = dds, 182 .label = label, 183 .run = &delete_donau_run, 184 .cleanup = &delete_donau_cleanup 185 }; 186 187 return cmd; 188 } 189 190 }