Add tests

This commit is contained in:
clydebarrow 2025-01-06 18:11:35 +11:00
parent e7f977c32f
commit 45ff6050c3
5 changed files with 55 additions and 46 deletions

View File

@ -7,7 +7,6 @@
#include "esphome/components/watchdog/watchdog.h"
#include "esphome/core/application.h"
#include "esphome/core/defines.h"
#include "esphome/core/log.h"
namespace esphome {
@ -52,7 +51,7 @@ std::shared_ptr<HttpContainer> HttpRequestHost::start(std::string url, std::stri
httplib::Result result;
if (method == "GET") {
result = client.Get(path, h_headers, [&](const char *data, size_t data_length) {
ESP_LOGD(TAG, "Got data length: %d", data_length);
ESP_LOGV(TAG, "Got data length: %zu", data_length);
container->response_body_.insert(container->response_body_.end(), (const uint8_t *) data,
(const uint8_t *) data + data_length);
return true;

View File

@ -5,6 +5,7 @@
// MIT License
//
#ifdef USE_HOST
#ifndef CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_HTTPLIB_H
@ -9675,3 +9676,5 @@ inline SSL_CTX *Client::ssl_context() const {
#endif
#endif // CPPHTTPLIB_HTTPLIB_H
#endif

View File

@ -1,52 +1,9 @@
substitutions:
verify_ssl: "true"
<<: !include http_request.yaml
wifi:
ssid: MySSID
password: password1
esphome:
on_boot:
then:
- http_request.get:
url: https://esphome.io
headers:
Content-Type: application/json
on_error:
logger.log: "Request failed"
on_response:
then:
- logger.log:
format: "Response status: %d, Duration: %lu ms"
args:
- response->status_code
- (long) response->duration_ms
- http_request.post:
url: https://esphome.io
headers:
Content-Type: application/json
json:
key: value
- http_request.send:
method: PUT
url: https://esphome.io
headers:
Content-Type: application/json
body: "Some data"
http_request:
useragent: esphome/tagreader
timeout: 10s
verify_ssl: ${verify_ssl}
script:
- id: does_not_compile
parameters:
api_url: string
then:
- http_request.get:
url: "http://google.com"
ota:
- platform: http_request
on_begin:

View File

@ -0,0 +1,46 @@
substitutions:
verify_ssl: "true"
network:
esphome:
on_boot:
then:
- http_request.get:
url: https://esphome.io
headers:
Content-Type: application/json
on_error:
logger.log: "Request failed"
on_response:
then:
- logger.log:
format: "Response status: %d, Duration: %lu ms"
args:
- response->status_code
- (long) response->duration_ms
- http_request.post:
url: https://esphome.io
headers:
Content-Type: application/json
json:
key: value
- http_request.send:
method: PUT
url: https://esphome.io
headers:
Content-Type: application/json
body: "Some data"
http_request:
useragent: esphome/tagreader
timeout: 10s
verify_ssl: ${verify_ssl}
script:
- id: does_not_compile
parameters:
api_url: string
then:
- http_request.get:
url: "http://google.com"

View File

@ -0,0 +1,4 @@
substitutions:
verify_ssl: "true"
<<: !include http_request.yaml