-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtext_searializer_counter_test.cpp
102 lines (70 loc) · 2.61 KB
/
text_searializer_counter_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <text_serializer.h>
#include <sstream>
#include <gmock/gmock.h>
using namespace prometheus;
using namespace testing;
using namespace std;
namespace {
const map<string, string> SOME_LABELS = {
{"label1", "value1"},
{"label2", "value2"}
};
}
TEST(text_searializer_counter_test, without_family) {
constexpr auto EXPECTED = R"(# HELP total_count Total Request count.
# TYPE total_count counter
total_count 2.5
)";
metric_registry reg;
auto &total_counter_family = reg.make_counter(metric_family::builder("total_count", "Total Request count."));
auto &total_counter = total_counter_family.add();
total_counter.inc(2.5);
std::stringstream str;
text_serializer::write(str, reg);
ASSERT_THAT(str.str(), StrEq(EXPECTED));
}
TEST(text_searializer_counter_test, with_family) {
constexpr auto EXPECTED = R"(# HELP total_count Total Request count.
# TYPE total_count counter
total_count 1
)";
metric_registry reg;
auto &tag_family = reg.make_family(metric_family::builder("total_count", "Total Request count."));
auto &total_counter_family = reg.make_counter(tag_family);
auto &total_counter = total_counter_family.add();
total_counter.inc();
std::stringstream str;
text_serializer::write(str, reg);
ASSERT_THAT(str.str(), StrEq(EXPECTED));
}
TEST(text_searializer_counter_test, with_family_labels) {
constexpr auto EXPECTED = R"(# HELP total_count Total Request count.
# TYPE total_count counter
total_count{label1="value1",label2="value2",} 1
)";
metric_registry reg;
auto &tag_family = reg.make_family(metric_family::builder("total_count", "Total Request count.").with_labels(SOME_LABELS));
auto &total_counter_family = reg.make_counter(tag_family);
auto &total_counter = total_counter_family.add();
total_counter.inc();
std::stringstream str;
text_serializer::write(str, reg);
ASSERT_THAT(str.str(), StrEq(EXPECTED));
}
TEST(text_searializer_counter_test, multi_family_metric) {
constexpr auto EXPECTED = R"(# HELP total_count Total Request count.
# TYPE total_count counter
total_count{label1="value1",label2="value2",} 1
total_count{label1="value1",label2="value2",label3="value3",} 2
)";
metric_registry reg;
auto &tag_family = reg.make_family(metric_family::builder("total_count", "Total Request count.").with_labels(SOME_LABELS));
auto &total_counter_family = reg.make_counter(tag_family);
auto &total_counter0 = total_counter_family.add();
total_counter0.inc();
auto &total_counter1 = total_counter_family.add({{"label3", "value3"}});
total_counter1.inc(2);
std::stringstream str;
text_serializer::write(str, reg);
ASSERT_THAT(str.str(), StrEq(EXPECTED));
}