mqtt schema test

This commit is contained in:
fengzero
2025-01-08 06:54:33 +00:00
parent 5711d5ca46
commit fa1964304f
2 changed files with 39 additions and 0 deletions
+8
View File
@@ -85,6 +85,14 @@ target_include_directories(cid_test PRIVATE
)
target_link_libraries(cid_test neuron-base gtest_main gtest)
add_executable(mqtt_schema_test mqtt_schema_test.cc ${CMAKE_SOURCE_DIR}/plugins/mqtt/schema.c)
target_include_directories(mqtt_schema_test PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/plugins
)
target_link_libraries(mqtt_schema_test neuron-base gtest_main gtest)
include(GoogleTest)
gtest_discover_tests(json_test)
gtest_discover_tests(http_test)
+31
View File
@@ -0,0 +1,31 @@
#include <gtest/gtest.h>
#include "neuron.h"
#include "mqtt/schema.h"
int64_t global_timestamp = 0;
zlog_category_t *neuron = NULL;
TEST(validate_success, schema)
{
const char *schema =
"{\"timestamp\":\"${timestamp}\",\"node\":\"${node}\",\"group\":\"${"
"group}\",\"tags\":\"${tag_values}\",\"static\":\"${static_"
"tags}\",\"errors\":\"${tag_errors}\"}";
mqtt_schema_vt_t *vts;
size_t n_vts;
int ret = mqtt_schema_validate(schema, &vts, &n_vts);
EXPECT_EQ(ret, 0);
EXPECT_EQ(n_vts, 6);
free(vts);
}
int main(int argc, char **argv)
{
zlog_init("./config/dev.conf");
neuron = zlog_get_category("neuron");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}