diff options
author | 2018-05-09 11:10:21 -0700 | |
---|---|---|
committer | 2018-06-05 16:59:25 -0700 | |
commit | c3c6e064b33ab8b7a2d3cf5a56171029d0bb1edc (patch) | |
tree | 3dce184ad675ba2ff3adbaf034209a0076c03754 /test/cpp/util | |
parent | b69f1f6aacad86bdc72e25085d74e64f17f32195 (diff) |
Add basic support for GetChannel
Diffstat (limited to 'test/cpp/util')
-rw-r--r-- | test/cpp/util/channel_trace_proto_helper.cc | 34 | ||||
-rw-r--r-- | test/cpp/util/channel_trace_proto_helper.h | 1 |
2 files changed, 26 insertions, 9 deletions
diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc index c395f607f4..db9390163b 100644 --- a/test/cpp/util/channel_trace_proto_helper.cc +++ b/test/cpp/util/channel_trace_proto_helper.cc @@ -30,26 +30,42 @@ namespace grpc { namespace testing { -void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str) { - std::string tracer_json_str(tracer_json_c_str); - grpc::channelz::v1::ChannelTrace channel_trace; +namespace { + +// Generic helper that takes in a json string, converts it to a proto, and +// then back to json. This ensures that the json string was correctly formatted +// according to https://developers.google.com/protocol-buffers/docs/proto3#json +template <typename Message> +void VaidateProtoJsonTranslation(char* json_c_str) { + std::string json_str(json_c_str); + Message msg; google::protobuf::util::JsonParseOptions parse_options; // If the following line is failing, then uncomment the last line of the // comment, and uncomment the lines that print the two strings. You can // then compare the output, and determine what fields are missing. // // parse_options.ignore_unknown_fields = true; - ASSERT_EQ(google::protobuf::util::JsonStringToMessage( - tracer_json_str, &channel_trace, parse_options), + ASSERT_EQ(google::protobuf::util::JsonStringToMessage(json_str, &msg, + parse_options), google::protobuf::util::Status::OK); std::string proto_json_str; - ASSERT_EQ(google::protobuf::util::MessageToJsonString(channel_trace, - &proto_json_str), + ASSERT_EQ(google::protobuf::util::MessageToJsonString(msg, &proto_json_str), google::protobuf::util::Status::OK); // uncomment these to compare the the json strings. - // gpr_log(GPR_ERROR, "tracer json: %s", tracer_json_str.c_str()); + // gpr_log(GPR_ERROR, "tracer json: %s", json_str.c_str()); // gpr_log(GPR_ERROR, "proto json: %s", proto_json_str.c_str()); - ASSERT_EQ(tracer_json_str, proto_json_str); + ASSERT_EQ(json_str, proto_json_str); +} + +} // namespace + +void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str) { + VaidateProtoJsonTranslation<grpc::channelz::v1::ChannelTrace>( + tracer_json_c_str); +} + +void ValidateChannelProtoJsonTranslation(char* channel_json_c_str) { + VaidateProtoJsonTranslation<grpc::channelz::v1::Channel>(channel_json_c_str); } } // namespace testing diff --git a/test/cpp/util/channel_trace_proto_helper.h b/test/cpp/util/channel_trace_proto_helper.h index d7043d9f06..d1a3603372 100644 --- a/test/cpp/util/channel_trace_proto_helper.h +++ b/test/cpp/util/channel_trace_proto_helper.h @@ -23,6 +23,7 @@ namespace grpc { namespace testing { void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str); +void ValidateChannelProtoJsonTranslation(char* channel_json_c_str); } // namespace testing } // namespace grpc |