From bffccc585a771692a18c3d11c295bcd840c5093a Mon Sep 17 00:00:00 2001 From: Jakob Date: Sun, 7 Dec 2025 11:32:37 +0100 Subject: [PATCH] test: add tests for /api/system/metrics endpoint --- test/test_api/test_api.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/test_api/test_api.cpp b/test/test_api/test_api.cpp index 66b90b754..2482f1dfb 100644 --- a/test/test_api/test_api.cpp +++ b/test/test_api/test_api.cpp @@ -318,6 +318,32 @@ void manual_test9() { } } +void manual_test10() { + const char * response = call_url("/api/system/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); + + // Check for some expected system metrics + TEST_ASSERT_TRUE(strstr(response, "emsesp_system_") != nullptr || strstr(response, "emsesp_network_") != nullptr + || strstr(response, "emsesp_api_") != nullptr); + + // Check for _info metrics if present + if (strstr(response, "_info") != nullptr) { + TEST_ASSERT_TRUE(strstr(response, "_info{") != nullptr || strstr(response, "_info ") != nullptr); + } + + // Check for device metrics if devices are present + if (strstr(response, "device") != nullptr) { + TEST_ASSERT_TRUE(strstr(response, "emsesp_device_") != nullptr); + } +} + void run_manual_tests() { RUN_TEST(manual_test1); RUN_TEST(manual_test2); @@ -328,6 +354,7 @@ void run_manual_tests() { RUN_TEST(manual_test7); RUN_TEST(manual_test8); RUN_TEST(manual_test9); + RUN_TEST(manual_test10); } const char * run_console_command(const char * command) { @@ -411,6 +438,7 @@ void create_tests() { // system capture("/api/system"); capture("/api/system/info"); + capture("/api/system/metrics"); capture("/api/system/settings/locale"); capture("/api/system/fetch"); capture("/api/system/network/values");