diff options
| author | fumingwei <[email protected]> | 2023-03-14 20:22:26 +0800 |
|---|---|---|
| committer | fumingwei <[email protected]> | 2023-03-14 20:22:26 +0800 |
| commit | c133ffc00b0e6029e84051ca2bcb423e9dcbd28f (patch) | |
| tree | 6ae925da015259b229c078f10e90f8271c94e245 /test | |
| parent | 9dbf155d1f115d588b88ffb5eac86e08e2222c1f (diff) | |
feature:构建gtest使用环境
Diffstat (limited to 'test')
| -rw-r--r-- | test/fieldstat_test.cpp | 2 | ||||
| -rw-r--r-- | test/src/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | test/src/gtest_fieldstat.cpp | 54 |
3 files changed, 66 insertions, 1 deletions
diff --git a/test/fieldstat_test.cpp b/test/fieldstat_test.cpp index 4765298..eefc224 100644 --- a/test/fieldstat_test.cpp +++ b/test/fieldstat_test.cpp @@ -282,7 +282,7 @@ int main(int argc, char *argv[]) { int ret = 0; - struct fieldstat_instance *test_instance = fieldstat_instance_create("test");; + struct fieldstat_instance *test_instance = fieldstat_instance_create("test"); if(test_instance == NULL) { diff --git a/test/src/CMakeLists.txt b/test/src/CMakeLists.txt new file mode 100644 index 0000000..fae7312 --- /dev/null +++ b/test/src/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8) + +include_directories(${PROJECT_SOURCE_DIR}/inc/) +include_directories(${PROJECT_SOURCE_DIR}/src/) + + +#add_executable(gtest_rule ${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp ${PROJECT_SOURCE_DIR}/src/tsg_bridge.cpp ${PROJECT_SOURCE_DIR}/src/tsg_leaky_bucket.cpp gtest_common.cpp gtest_rule.cpp) +#target_link_libraries(gtest_rule gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger MESA_jump_layer MESA_field_stat2 maatframe) + +add_executable(gtest_fieldstat ${SRC} gtest_fieldstat.cpp) +target_link_libraries(gtest_fieldstat gtest-static) diff --git a/test/src/gtest_fieldstat.cpp b/test/src/gtest_fieldstat.cpp new file mode 100644 index 0000000..9850d7f --- /dev/null +++ b/test/src/gtest_fieldstat.cpp @@ -0,0 +1,54 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <gtest/gtest.h> +#include "fieldstat.h" +#include "fieldstat_internal.h" + +extern struct prometheus_endpoint_instance g_prometheus_endpoint_instance; + +TEST(FeildStatAPI, CreateFieldStatInstance) +{ + struct fieldstat_instance *instance = fieldstat_instance_create("test"); + EXPECT_NE(nullptr, instance); + EXPECT_STREQ("test", instance->name); +} + +TEST(FeildStatAPI, FieldStatEnablePrometheusEndpoint) +{ + int ret_enable_prometheus_endpoint = 0; + int ret_req_prometheus_endpoint = 0; + + ret_enable_prometheus_endpoint = fieldstat_global_enable_prometheus_endpoint(9020, "/metrcis"); + EXPECT_EQ(0, ret_enable_prometheus_endpoint); + + ret_req_prometheus_endpoint = system("curl http://127.0.0.1:9020/metrics"); + EXPECT_EQ(0,ret_req_prometheus_endpoint); +} + +TEST(FeildStatAPI, FieldStatSetPrometheusOutput) +{ + struct fieldstat_instance *instance = NULL; + int ret_enable_prometheus_endpoint = 0; + int ret_set_prometheus_output = 0; + + instance = fieldstat_instance_create("test"); + EXPECT_STREQ("test", instance->name); + + ret_enable_prometheus_endpoint = fieldstat_global_enable_prometheus_endpoint(9020, "/metrcis"); + EXPECT_EQ(0, ret_enable_prometheus_endpoint); + + ret_set_prometheus_output = fieldstat_set_prometheus_output(instance); + EXPECT_EQ(0, ret_set_prometheus_output); + + EXPECT_EQ(1, g_prometheus_endpoint_instance.running); + EXPECT_EQ(instance, g_prometheus_endpoint_instance.fs_instance[0]); + EXPECT_EQ(1, g_prometheus_endpoint_instance.fs_instance_cnt); +} + +int main(int argc, char *argv[]) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); + return 0; +}
\ No newline at end of file |
