diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | test/test_exporter_local.cpp | 86 |
2 files changed, 88 insertions, 1 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9d9d8b6..aedc2a1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -58,4 +58,5 @@ add_unit_test(test_register_and_reset) add_unit_test(test_serialize)
add_unit_test(unit_test_cell_manager)
add_unit_test(test_exporter_interface)
-add_unit_test(test_exporter_prometheus)
\ No newline at end of file +add_unit_test(test_exporter_prometheus)
+add_unit_test(test_exporter_local)
\ No newline at end of file diff --git a/test/test_exporter_local.cpp b/test/test_exporter_local.cpp new file mode 100644 index 0000000..5915caf --- /dev/null +++ b/test/test_exporter_local.cpp @@ -0,0 +1,86 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <gtest/gtest.h> +#include "fieldstat.h" +#include "fieldstat_exporter.h" +#include "cjson/cJSON.h" + +/******************************************************************************* + * case: output counter +*******************************************************************************/ + +static struct fieldstat *create_fieldstat_MetricTypeCounter() +{ + const char *metric_name[] = { + "version", "threads", "tables", "plug_cached", "plug_acc", "group", + "not_grp", "compile", "garbage_num", "outer_mid", "scan_bytes", + "scan_times", "update_err", "scan_error", "z_stream","nt_grp_hit", + "cmd_commit", "cmd_in_q", "line_cmd/s"}; + + struct fieldstat *instance = fieldstat_new(); + EXPECT_NE(nullptr, instance); + + int cube_id = fieldstat_register_cube(instance, NULL, 0, + SAMPLING_MODE_COMPREHENSIVE, 3); + EXPECT_EQ(0, cube_id); + + for(unsigned int i= 0; i < sizeof(metric_name)/sizeof(metric_name[0]); i++) + { + int counter_id = fieldstat_register_counter(instance, cube_id, + metric_name[i], + COUNTER_MERGE_BY_SUM); + int cell_id = fieldstat_cube_add(instance, cube_id, NULL, 0, 1); + EXPECT_EQ(0, cell_id); + if(cell_id >= 0) + { + fieldstat_counter_incrby(instance, cube_id, counter_id, cell_id, i); + } + } + EXPECT_NE(nullptr, instance); + + return instance; +} + + + + +TEST(ExporterLocal, MetricTypeCounter) + +{ + int ret = 0; + struct fieldstat_exporter *exporter = NULL; + struct fieldstat *instance = NULL; + // input start + const char *exporter_name = "firewall"; + + exporter = fieldstat_exporter_new(exporter_name, NULL, 0); + EXPECT_NE(nullptr, exporter); + + ret = fieldstat_exporter_enable_prometheus_exporter(exporter); + EXPECT_EQ(0, ret); + + ret = fieldstat_exporter_set_local_exporter(exporter, "/tmp/fs4_exporter"); + EXPECT_EQ(0, ret); + + fieldstat_exporter_start(exporter); + + instance = create_fieldstat_MetricTypeCounter(); + + ret = fieldstat_exporter_merge_fieldstat(exporter, &instance, 1); + EXPECT_EQ(0, ret); + + ret = fieldstat_exporter_local_export(exporter); + EXPECT_EQ(0, ret); + + fieldstat_exporter_free(exporter); + fieldstat_free(instance); +} + + + +int main(int argc, char *argv[]) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}
\ No newline at end of file |
