1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include <nlohmann_json/json.hpp>
- #include "kbf.h"
- #include "kbf/wifi.h"
- #include "kbf/http/server.h"
- #include "kbf/http/client.h"
- #include "kbf/rtos.h"
- #include <unity.h>
- using namespace kbf;
- using namespace std;
- using nlohmann::json;
- TEST_CASE("HTTPS GET", "[kbf_http]") {
- wifi::start();
- auto server = http::Server();
- TEST_ASSERT_FALSE(server.isRunning())
- http::Response (*handleGet)(const http::Request &, void *) = {[](const http::Request &request, void *) {
- TEST_ASSERT_EQUAL(http::GET, request.method);
- return http::Response("OK");
- }};
- server.route({http::GET, "/get-me", handleGet, nullptr});
- server.startSSL();
- TEST_ASSERT_TRUE(server.isRunning())
- auto client = http::Client();
- auto response = client.get("https://localhost/get-me");
- TEST_ASSERT_EQUAL(200, response->status);
- TEST_ASSERT_EQUAL_STRING("OK", response->body.c_str());
- server.stop();
- wifi::stop();
- }
- // TODO KBF-22 fix async test
- static rtos::EventGroup eventGroup;
- TEST_CASE("HTTPS async", "[broken]") {
- wifi::start();
- http::Response (*handleRequest)(const http::Request &, void *) = {[](const http::Request &request, void *) {
- auto response = http::Response("OK");
- kbf::sleep(100);
- return response;
- }};
- auto server = http::Server()
- .route({http::GET, "/", handleRequest, nullptr})
- .startSSL();
- auto client = http::Client(true);
- client.onSuccess = {[](http::Client &client, const http::Response &response) {
- TEST_ASSERT_EQUAL_STRING("OK", response.body.data());
- eventGroup.setBit(0);
- }};
- auto response = client.get("https://localhost/");
- TEST_ASSERT_NULL(response)
- TEST_ASSERT_EQUAL(0, eventGroup.getBit(0));
- kbf::sleep(200);
- TEST_ASSERT_EQUAL(1, eventGroup.getBit(0));
- server.stop();
- wifi::stop();
- }
|