mirror of
https://github.com/esphome/esphome.git
synced 2025-02-12 01:02:06 +01:00
Add tests
This commit is contained in:
parent
e7f977c32f
commit
45ff6050c3
@ -7,7 +7,6 @@
|
|||||||
#include "esphome/components/watchdog/watchdog.h"
|
#include "esphome/components/watchdog/watchdog.h"
|
||||||
|
|
||||||
#include "esphome/core/application.h"
|
#include "esphome/core/application.h"
|
||||||
#include "esphome/core/defines.h"
|
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
@ -52,7 +51,7 @@ std::shared_ptr<HttpContainer> HttpRequestHost::start(std::string url, std::stri
|
|||||||
httplib::Result result;
|
httplib::Result result;
|
||||||
if (method == "GET") {
|
if (method == "GET") {
|
||||||
result = client.Get(path, h_headers, [&](const char *data, size_t data_length) {
|
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,
|
container->response_body_.insert(container->response_body_.end(), (const uint8_t *) data,
|
||||||
(const uint8_t *) data + data_length);
|
(const uint8_t *) data + data_length);
|
||||||
return true;
|
return true;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
// MIT License
|
// MIT License
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#ifdef USE_HOST
|
||||||
#ifndef CPPHTTPLIB_HTTPLIB_H
|
#ifndef CPPHTTPLIB_HTTPLIB_H
|
||||||
#define CPPHTTPLIB_HTTPLIB_H
|
#define CPPHTTPLIB_HTTPLIB_H
|
||||||
|
|
||||||
@ -9675,3 +9676,5 @@ inline SSL_CTX *Client::ssl_context() const {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // CPPHTTPLIB_HTTPLIB_H
|
#endif // CPPHTTPLIB_HTTPLIB_H
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -1,52 +1,9 @@
|
|||||||
substitutions:
|
<<: !include http_request.yaml
|
||||||
verify_ssl: "true"
|
|
||||||
|
|
||||||
wifi:
|
wifi:
|
||||||
ssid: MySSID
|
ssid: MySSID
|
||||||
password: password1
|
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:
|
ota:
|
||||||
- platform: http_request
|
- platform: http_request
|
||||||
on_begin:
|
on_begin:
|
||||||
|
46
tests/components/http_request/http_request.yaml
Normal file
46
tests/components/http_request/http_request.yaml
Normal 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"
|
4
tests/components/http_request/test.host.yaml
Normal file
4
tests/components/http_request/test.host.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
substitutions:
|
||||||
|
verify_ssl: "true"
|
||||||
|
|
||||||
|
<<: !include http_request.yaml
|
Loading…
Reference in New Issue
Block a user