MCPcopy Create free account
hub / github.com/FastLED/FastLED / runHttpGetTest

Function runHttpGetTest

examples/AutoResearch/AutoResearchNet.cpp:212–251  ·  view source on GitHub ↗

@brief Run a single HTTP GET test and return result

Source from the content-addressed store, hash-verified

210
211/// @brief Run a single HTTP GET test and return result
212static fl::json runHttpGetTest(const char* url, const char* test_name) {
213 fl::json result = fl::json::object();
214 result.set("test", test_name);
215
216 esp_http_client_config_t config = {};
217 config.url = url;
218 config.timeout_ms = 5000;
219
220 esp_http_client_handle_t client = esp_http_client_init(&config);
221 if (!client) {
222 result.set("passed", false);
223 result.set("error", "Failed to init HTTP client");
224 return result;
225 }
226
227 esp_err_t err = esp_http_client_perform(client);
228 if (err != ESP_OK) {
229 result.set("passed", false);
230 fl::sstream ss;
231 ss << "HTTP request failed: " << esp_err_to_name(err);
232 result.set("error", ss.str().c_str());
233 esp_http_client_cleanup(client);
234 return result;
235 }
236
237 int status = esp_http_client_get_status_code(client);
238 result.set("status_code", static_cast<int64_t>(status));
239
240 if (status != 200) {
241 result.set("passed", false);
242 fl::sstream ss;
243 ss << "Expected status 200, got " << status;
244 result.set("error", ss.str().c_str());
245 } else {
246 result.set("passed", true);
247 }
248
249 esp_http_client_cleanup(client);
250 return result;
251}
252
253// ============================================================================
254// Public API

Callers 2

runNetClientTestFunction · 0.85
runNetLoopbackFunction · 0.85

Calls 4

esp_err_to_nameFunction · 0.85
setMethod · 0.45
c_strMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected