Files
cpp-project-template/third_party/prometheus/push/tests/internal/label_encoder_test.cc
tqcq c68893bace
Some checks failed
sm-rpc / build (Debug, aarch64-linux-gnu) (push) Failing after 29s
sm-rpc / build (Debug, arm-linux-gnueabihf) (push) Failing after 16s
sm-rpc / build (Debug, host.gcc) (push) Failing after 11s
sm-rpc / build (Debug, mipsel-linux-gnu) (push) Failing after 12s
sm-rpc / build (Release, aarch64-linux-gnu) (push) Failing after 11s
sm-rpc / build (Release, arm-linux-gnueabihf) (push) Failing after 11s
sm-rpc / build (Release, host.gcc) (push) Failing after 12s
sm-rpc / build (Release, mipsel-linux-gnu) (push) Failing after 16s
feat add spdlog
2025-08-22 18:22:57 +08:00

44 lines
1.0 KiB
C++

#include "detail/label_encoder.h"
#include <gtest/gtest.h>
#include <sstream>
#include <string>
namespace prometheus {
namespace {
class LabelEncoderTest : public testing::Test {
protected:
std::string Encode(const Label& label) {
std::stringstream ss;
detail::encodeLabel(ss, label);
return ss.str();
}
};
// test cases taken from https://github.com/prometheus/pushgateway#url
TEST_F(LabelEncoderTest, regular) {
EXPECT_EQ("/foo/bar", Encode(Label{"foo", "bar"}));
}
TEST_F(LabelEncoderTest, empty) {
EXPECT_EQ("/first_label@base64/=", Encode(Label{"first_label", ""}));
}
TEST_F(LabelEncoderTest, path) {
EXPECT_EQ("/path@base64/L3Zhci90bXA=", Encode(Label{"path", "/var/tmp"}));
}
TEST_F(LabelEncoderTest, unicode) {
const char unicodeText[] =
"\xce\xa0\xcf\x81\xce\xbf\xce\xbc\xce\xb7\xce\xb8\xce\xb5\xcf\x8d\xcf"
"\x82"; // Προμηθεύς
EXPECT_EQ("/name@base64/zqDPgc6_zrzOt864zrXPjc-C",
Encode(Label{"name", unicodeText}));
}
} // namespace
} // namespace prometheus