Skip to content

Commit 302c572

Browse files
authored
Add unit test of MessageUtil::anyToBytes (#15326)
Added a missing unittest in #15210 resolves #15210 (comment) Signed-off-by: Takeshi Yoneda takeshi@tetrate.io Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
1 parent 07c4c17 commit 302c572

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

source/common/protobuf/utility.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class MessageUtil {
331331

332332
/**
333333
* Convert from google.protobuf.Any to bytes as std::string
334-
* @param message source google.protobuf.Any message.
334+
* @param any source google.protobuf.Any message.
335335
*
336336
* @return std::string consists of bytes in the input message.
337337
*/

test/common/protobuf/utility_test.cc

+23
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,29 @@ TEST_F(ProtobufUtilityTest, HashedValueStdHash) {
12491249
EXPECT_NE(set.find(hv3), set.end());
12501250
}
12511251

1252+
TEST_F(ProtobufUtilityTest, AnyBytes) {
1253+
{
1254+
ProtobufWkt::StringValue source;
1255+
source.set_value("abc");
1256+
ProtobufWkt::Any source_any;
1257+
source_any.PackFrom(source);
1258+
EXPECT_EQ(MessageUtil::anyToBytes(source_any), "abc");
1259+
}
1260+
{
1261+
ProtobufWkt::BytesValue source;
1262+
source.set_value({0x01, 0x02, 0x03});
1263+
ProtobufWkt::Any source_any;
1264+
source_any.PackFrom(source);
1265+
EXPECT_EQ(MessageUtil::anyToBytes(source_any), "\x01\x02\x03");
1266+
}
1267+
{
1268+
envoy::config::cluster::v3::Filter filter;
1269+
ProtobufWkt::Any source_any;
1270+
source_any.PackFrom(filter);
1271+
EXPECT_EQ(MessageUtil::anyToBytes(source_any), source_any.value());
1272+
}
1273+
}
1274+
12521275
// MessageUtility::anyConvert() with the wrong type throws.
12531276
TEST_F(ProtobufUtilityTest, AnyConvertWrongType) {
12541277
ProtobufWkt::Duration source_duration;

0 commit comments

Comments
 (0)