Skip to content

Commit

Permalink
changed rds_impl_test.cc to adhere to new formatted print
Browse files Browse the repository at this point in the history
Signed-off-by: Rama <[email protected]>
  • Loading branch information
ramaraochavali committed Jan 29, 2018
1 parent 6bc4587 commit 195f256
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 20 deletions.
4 changes: 0 additions & 4 deletions source/common/protobuf/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ std::string MessageUtil::getJsonStringFromMessage(const Protobuf::Message& messa
return json;
}

std::string MessageUtil::getJsonStringFromMessage(const Protobuf::Message& message) {
return getJsonStringFromMessage(message, false);
}

void MessageUtil::jsonConvert(const Protobuf::Message& source, Protobuf::Message& dest) {
// TODO(htuch): Consolidate with the inflight cleanups here.
Protobuf::util::JsonOptions json_options;
Expand Down
9 changes: 1 addition & 8 deletions source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,14 @@ class MessageUtil {
*/
static void jsonConvert(const Protobuf::Message& source, Protobuf::Message& dest);

/**
* Extract JSON as string from a google.protobuf.Message.
* @param message message of type type.googleapis.com/google.protobuf.Message.
* @return std::string of JSON object.
*/
static std::string getJsonStringFromMessage(const Protobuf::Message& message);

/**
* Extract JSON as string from a google.protobuf.Message.
* @param message message of type type.googleapis.com/google.protobuf.Message.
* @param pretty_print whether the returned JSON should be formatted.
* @return std::string of formatted JSON object.
*/
static std::string getJsonStringFromMessage(const Protobuf::Message& message,
const bool pretty_print);
const bool pretty_print = false);

/**
* Extract JSON object from a google.protobuf.Message.
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/rds_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RdsRouteConfigProviderImpl::RdsRouteConfigProviderImpl(
if (rds.has_config_source()) {
config_source_ = MessageUtil::getJsonStringFromMessage(rds.config_source(), true);
} else {
config_source_ = "NOT_USING_CLUSTER";
config_source_ = "NO_CONFIG_SOURCE";
}
}

Expand Down
89 changes: 82 additions & 7 deletions test/common/router/rds_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,17 @@ TEST_F(RdsImplTest, Basic) {
{
"version_info": "",
"route_config_name": "foo_route_config",
"config_source": {"api_config_source":{"cluster_names":["foo_cluster"],"refresh_delay":"1s"}},
"config_source": {
"api_config_source": {
"cluster_names": [
"foo_cluster"
],
"refresh_delay": "1s"
}
}
,
"route_table_dump": {}
}
]
)EOF";
Expand Down Expand Up @@ -248,8 +257,19 @@ TEST_F(RdsImplTest, Basic) {
{
"version_info": "hash_15ed54077da94d8b",
"route_config_name": "foo_route_config",
"config_source": {"api_config_source":{"cluster_names":["foo_cluster"],"refresh_delay":"1s"}},
"route_table_dump": {"name":"foo_route_config"}
"config_source": {
"api_config_source": {
"cluster_names": [
"foo_cluster"
],
"refresh_delay": "1s"
}
}
,
"route_table_dump": {
"name": "foo_route_config"
}
}
]
)EOF";
Expand Down Expand Up @@ -327,8 +347,45 @@ TEST_F(RdsImplTest, Basic) {
{
"version_info": "hash_7a3f97b327d08382",
"route_config_name": "foo_route_config",
"config_source": {"api_config_source":{"cluster_names":["foo_cluster"],"refresh_delay":"1s"}},
"route_table_dump": {"name":"foo_route_config","virtual_hosts":[{"name":"local_service","domains":["*"],"routes":[{"match":{"prefix":"/foo"},"route":{"cluster_header":":authority"}},{"match":{"prefix":"/bar"},"route":{"cluster":"bar"}}]}]}
"config_source": {
"api_config_source": {
"cluster_names": [
"foo_cluster"
],
"refresh_delay": "1s"
}
}
,
"route_table_dump": {
"name": "foo_route_config",
"virtual_hosts": [
{
"name": "local_service",
"domains": [
"*"
],
"routes": [
{
"match": {
"prefix": "/foo"
},
"route": {
"cluster_header": ":authority"
}
},
{
"match": {
"prefix": "/bar"
},
"route": {
"cluster": "bar"
}
}
]
}
]
}
}
]
)EOF";
Expand Down Expand Up @@ -524,14 +581,32 @@ TEST_F(RouteConfigProviderManagerImplTest, Basic) {
{
"version_info": "",
"route_config_name": "foo_route_config",
"config_source": {"api_config_source":{"cluster_names":["bar_cluster"],"refresh_delay":"1s"}},
"config_source": {
"api_config_source": {
"cluster_names": [
"bar_cluster"
],
"refresh_delay": "1s"
}
}
,
"route_table_dump": {}
}
,{
"version_info": "",
"route_config_name": "foo_route_config",
"config_source": {"api_config_source":{"cluster_names":["foo_cluster"],"refresh_delay":"1s"}},
"config_source": {
"api_config_source": {
"cluster_names": [
"foo_cluster"
],
"refresh_delay": "1s"
}
}
,
"route_table_dump": {}
}
]
)EOF";
Expand Down

0 comments on commit 195f256

Please sign in to comment.