Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unicode ut for TextParser #1899

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions core/unittest/prometheus/TextParserUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TextParserUnittest : public testing::Test {
void TestParseMultipleLines() const;
void TestParseMetricWithTagsAndTimestamp() const;
void TestParseMetricWithManyTags() const;
void TestParseUnicodeLabelValue();

void TestParseFaliure();
void TestParseSuccess();
Expand Down Expand Up @@ -360,6 +361,33 @@ void TextParserUnittest::TestHonorTimestamps() {

UNIT_TEST_CASE(TextParserUnittest, TestHonorTimestamps)

void TextParserUnittest::TestParseUnicodeLabelValue() {
auto parser = TextParser();
string rawData
= R"""(container_blkio_device_usage_total{container="",device="/dev/nvme0n1中文",id="/😀",image="",major="259",minor="0",name="",namespace="",operation="Async",pod=""} 9.9410452992e+10 1715829785083)""";
const auto eGroup = parser.Parse(rawData, 1715829785, 83000000);
const auto& events = &eGroup.GetEvents();
APSARA_TEST_EQUAL(1UL, events->size());
const auto& event = events->front();
const auto& metric = event.Get<MetricEvent>();
APSARA_TEST_EQUAL("container_blkio_device_usage_total", metric->GetName().to_string());
APSARA_TEST_EQUAL(1715829785, metric->GetTimestamp());
APSARA_TEST_TRUE(IsDoubleEqual(9.9410452992e+10, metric->GetValue<UntypedSingleValue>()->mValue));

APSARA_TEST_EQUAL("", metric->GetTag("container").to_string());
APSARA_TEST_EQUAL("/dev/nvme0n1中文", metric->GetTag("device").to_string());
APSARA_TEST_EQUAL("/😀", metric->GetTag("id").to_string());
APSARA_TEST_EQUAL("", metric->GetTag("image").to_string());
APSARA_TEST_EQUAL("259", metric->GetTag("major").to_string());
APSARA_TEST_EQUAL("0", metric->GetTag("minor").to_string());
APSARA_TEST_EQUAL("", metric->GetTag("name").to_string());
APSARA_TEST_EQUAL("", metric->GetTag("namespace").to_string());
APSARA_TEST_EQUAL("Async", metric->GetTag("operation").to_string());
APSARA_TEST_EQUAL("", metric->GetTag("pod").to_string());
}

UNIT_TEST_CASE(TextParserUnittest, TestParseUnicodeLabelValue)

} // namespace logtail

UNIT_TEST_MAIN
Loading