From b44a0d68136718269df81a4beaef8b471a3a6431 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sun, 30 Nov 2025 10:37:34 +0100 Subject: [PATCH] test: add tests for api/metrics endpoint --- src/core/command.cpp | 2 ++ src/core/locale_translations.h | 1 + test/test_api/test_api.cpp | 35 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/core/command.cpp b/src/core/command.cpp index e71be6b88..a13468fdf 100644 --- a/src/core/command.cpp +++ b/src/core/command.cpp @@ -763,6 +763,8 @@ void Command::show_all(uuid::console::Shell & shell) { shell.println(COLOR_RESET); shell.printf(" entities \t\t\t%slist all entities %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN); shell.println(COLOR_RESET); + shell.printf(" metrics \t\t\t%slist all prometheus metrics %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_GREEN); + shell.println(COLOR_RESET); // show system ones first show(shell, EMSdevice::DeviceType::SYSTEM, true); diff --git a/src/core/locale_translations.h b/src/core/locale_translations.h index f5ce7ce07..c3c125b0f 100644 --- a/src/core/locale_translations.h +++ b/src/core/locale_translations.h @@ -63,6 +63,7 @@ MAKE_WORD_TRANSLATION(pool_device, "Pool Module", "Poolmodul", "", "Poolmodul", MAKE_WORD_TRANSLATION(info_cmd, "list all values (verbose)", "Liste aller Werte", "lijst van alle waardes", "lista alla värden", "wyświetl wszystkie wartości", "Viser alle verdier", "", "Tüm değerleri listele", "elenca tutti i valori", "zobraziť všetky hodnoty", "vypsat všechny hodnoty (podrobně)") // TODO translate MAKE_WORD_TRANSLATION(commands_cmd, "list all commands", "Liste aller Kommandos", "lijst van alle commando's", "lista alla kommandon", "wyświetl wszystkie komendy", "Viser alle kommandoer", "", "Tüm komutları listele", "elencaa tutti i comandi", "zobraziť všetky príkazy", "vypsat všechny příkazy") // TODO translate MAKE_WORD_TRANSLATION(entities_cmd, "list all entities", "Liste aller Entitäten", "lijst van alle entiteiten", "lista all entiteter", "wyświetl wszsytkie encje", "Viser alle enheter", "", "Tüm varlıkları listele", "elenca tutte le entità", "zobraziť všetky entity", "vypsat všechny entity") // TODO translate +MAKE_WORD_TRANSLATION(metrics_cmd, "list all prometheus metrics", "Liste aller Prometheus Metriken", "lijst van alle Prometheus metriken", "lista alla Prometheus metriker", "wyświetl wszystkie Prometheus metryki", "Viser alle Prometheus metrikker", "", "Tüm Prometheus metriklerini listele", "elenca tutte le metriche Prometheus", "zobraziť všetky Prometheus metriky", "vypsat všechny Prometheus metriky") // TODO translate MAKE_WORD_TRANSLATION(send_cmd, "send a telegram", "Sende EMS-Telegramm", "stuur een telegram", "skicka ett telegram", "wyślij telegram", "send et telegram", "", "Bir telegram gönder", "invia un telegramma", "poslať telegram", "odeslat telegram") // TODO translate MAKE_WORD_TRANSLATION(read_cmd, "send read request", "", "", "skicka en läsförfrågan", "", "", "", "", "", "odoslať žiadosť o prečítanie", "") // TODO translate MAKE_WORD_TRANSLATION(setiovalue_cmd, "set I/O value", "Setze Werte E/A", "instellen standaardwaarde", "sätt ett I/O-värde", "ustaw wartość", "sett en io verdi", "", "Giriş/Çıkış değerlerini ayarla", "imposta valore io", "nastaviť hodnotu io", "nastavit hodnotu I/O") // TODO translate diff --git a/test/test_api/test_api.cpp b/test/test_api/test_api.cpp index 14a3c1601..033270c02 100644 --- a/test/test_api/test_api.cpp +++ b/test/test_api/test_api.cpp @@ -288,6 +288,37 @@ void manual_test7() { TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/test_ram", data)); } +void manual_test8() { + const char * response = call_url("/api/boiler/metrics"); + + TEST_ASSERT_NOT_NULL(response); + TEST_ASSERT_TRUE(strlen(response) > 0); + + TEST_ASSERT_TRUE(strstr(response, "# HELP") != nullptr); + TEST_ASSERT_TRUE(strstr(response, "# TYPE") != nullptr); + TEST_ASSERT_TRUE(strstr(response, "emsesp_") != nullptr); + TEST_ASSERT_TRUE(strstr(response, " gauge") != nullptr); + + TEST_ASSERT_TRUE(strstr(response, "emsesp_tapwateractive") != nullptr || + strstr(response, "emsesp_selflowtemp") != nullptr || + strstr(response, "emsesp_curflowtemp") != nullptr); +} + +void manual_test9() { + const char * response = call_url("/api/thermostat/metrics"); + + TEST_ASSERT_NOT_NULL(response); + TEST_ASSERT_TRUE(strlen(response) > 0); + + TEST_ASSERT_TRUE(strstr(response, "# HELP") != nullptr); + TEST_ASSERT_TRUE(strstr(response, "# TYPE") != nullptr); + TEST_ASSERT_TRUE(strstr(response, "emsesp_") != nullptr); + + if (strstr(response, "circuit=") != nullptr) { + TEST_ASSERT_TRUE(strstr(response, "{circuit=") != nullptr); + } +} + void run_manual_tests() { RUN_TEST(manual_test1); RUN_TEST(manual_test2); @@ -296,6 +327,8 @@ void run_manual_tests() { RUN_TEST(manual_test5); RUN_TEST(manual_test6); RUN_TEST(manual_test7); + RUN_TEST(manual_test8); + RUN_TEST(manual_test9); } const char * run_console_command(const char * command) { @@ -353,6 +386,7 @@ void create_tests() { capture("/api/boiler/values"); capture("/api/boiler/info"); // capture("/api/boiler/entities"); // skipping since payload is too large + capture("/api/boiler/metrics"); capture("/api/boiler/comfort"); capture("/api/boiler/comfort/value"); capture("/api/boiler/comfort/fullname"); @@ -364,6 +398,7 @@ void create_tests() { // thermostat capture("/api/thermostat"); capture("/api/thermostat/hc1/values"); + capture("/api/thermostat/metrics"); capture("/api/thermostat/hc1/seltemp"); capture("/api/thermostat/hc2/seltemp");