add console tests to Unity

This commit is contained in:
proddy
2024-08-06 10:33:22 +02:00
parent 3045144cc3
commit 7b6fe53e74
7 changed files with 118 additions and 28 deletions

View File

@@ -691,11 +691,16 @@ std::string EMSESPShell::context_text() {
// when in su (admin) show # as the prompt suffix
std::string EMSESPShell::prompt_suffix() {
#ifndef EMSESP_UNITY
if (has_flags(CommandFlags::ADMIN)) {
return std::string{'#'};
} else {
return std::string{'$'};
}
#else
// don't bother with prompt suffix if we're testing Unity output
return "";
#endif
}
void EMSESPShell::end_of_transmission() {

View File

@@ -1553,8 +1553,6 @@ void EMSESP::start() {
#if defined(EMSESP_STANDALONE)
shell_->add_flags(CommandFlags::ADMIN); // always start in su/admin mode when running tests
#endif
#else
#warning "Shell is disabled when running Unity tests."
#endif
// start the file system

View File

@@ -1397,8 +1397,13 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
JsonObject node;
// System
node = output["system"].to<JsonObject>();
node["version"] = EMSESP_APP_VERSION;
node = output["system"].to<JsonObject>();
// prevent false negataive in Unity tests everytime the version changes
#if defined(EMSESP_UNITY)
node["version"] = "dev";
#else
node["version"] = EMSESP_APP_VERSION;
#endif
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
node["uptimeSec"] = uuid::get_uptime_sec();
#ifndef EMSESP_STANDALONE

View File

@@ -1109,6 +1109,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
Serial.println();
Serial.printf("%s**** Testing bad urls ****\n%s", COLOR_RED, COLOR_RESET);
request.method(HTTP_GET);
request.url("/api/boiler2");
EMSESP::webAPIService.webAPIService(&request);

View File

@@ -134,7 +134,7 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
const char * api_data = output["api_data"];
if (api_data) {
request->send(200, "text/plain; charset=utf-8", api_data);
#if defined(EMSESP_TEST)
#if defined(EMSESP_UNITY)
// store the result so we can test with Unity later
storeResponse(output);
#endif
@@ -161,7 +161,7 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
request->send(response);
api_count_++;
#if defined(EMSESP_TEST)
#if defined(EMSESP_UNITY)
// store the result so we can test with Unity later
storeResponse(output);
#endif
@@ -229,7 +229,7 @@ void WebAPIService::getEntities(AsyncWebServerRequest * request) {
request->send(response);
}
#if defined(EMSESP_TEST)
#if defined(EMSESP_UNITY)
// store the result so we can test with Unity later
static JsonDocument storeResponseDoc_;