esp_http_client: added example test case to verify error code received when connecting to non-existent url

This commit is contained in:
David Cermak 2019-04-24 14:49:20 +02:00
parent a001eb39bf
commit dc16b8243f
2 changed files with 23 additions and 1 deletions

View File

@ -45,8 +45,9 @@ def test_examples_protocol_esp_http_client(env, extra_data):
dut1.expect(re.compile(r"HTTP Absolute path redirect Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTPS Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP redirect to HTTPS Status = 200, content_length = (\d)"), timeout=10)
dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = -1"))
dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"HTTP Stream reader Status = 200, content_length = (\d)"))
dut1.expect(re.compile(r"Last esp error code: 0x8001"))
dut1.expect("Finish http example")

View File

@ -492,6 +492,25 @@ static void https_async()
esp_http_client_cleanup(client);
}
static void https_with_invalid_url()
{
esp_http_client_config_t config = {
.url = "https://not.existent.url",
.event_handler = _http_event_handler,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
}
esp_http_client_cleanup(client);
}
static void http_test_task(void *pvParameters)
{
@ -508,6 +527,7 @@ static void http_test_task(void *pvParameters)
http_download_chunk();
http_perform_as_stream_reader();
https_async();
https_with_invalid_url();
ESP_LOGI(TAG, "Finish http example");
vTaskDelete(NULL);
@ -529,6 +549,7 @@ void app_main()
* examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(example_connect());
ESP_LOGI(TAG, "Connected to AP, begin http example");
xTaskCreate(&http_test_task, "http_test_task", 8192, NULL, 5, NULL);
}