Skip to content

Commit

Permalink
Add test of parsing weighted_cluster route configuration to improve t…
Browse files Browse the repository at this point in the history
…est coverage. (envoyproxy#6711)

Signed-off-by: Yan Avlasov <[email protected]>
  • Loading branch information
yanavlasov authored and mattklein123 committed May 1, 2019
1 parent bc9eec7 commit 4769552
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/common/config/rds_json_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,38 @@ TEST(RdsJsonTest, TestRuntimeFractionTranslation) {
EXPECT_EQ(route.match().runtime_fraction().runtime_key(), "some_key");
}

TEST(RdsJsonTest, TestWeightedClusterTranslation) {
const std::string json_string = R"EOF(
{
"prefix": "/new_endpoint",
"prefix_rewrite": "/api/new_endpoint",
"weighted_clusters": {
"clusters": [
{
"name": "foo",
"weight": 80
},
{
"name": "bar",
"weight": 20
}
]
}
}
)EOF";
envoy::api::v2::route::Route route;
auto json_object_ptr = Json::Factory::loadFromString(json_string);
Envoy::Config::RdsJson::translateRoute(*json_object_ptr, route);

EXPECT_TRUE(route.has_route());
EXPECT_TRUE(route.route().has_weighted_clusters());
EXPECT_EQ(2, route.route().weighted_clusters().clusters_size());
EXPECT_EQ("foo", route.route().weighted_clusters().clusters(0).name());
EXPECT_EQ(80, route.route().weighted_clusters().clusters(0).weight().value());
EXPECT_EQ("bar", route.route().weighted_clusters().clusters(1).name());
EXPECT_EQ(20, route.route().weighted_clusters().clusters(1).weight().value());
}

} // namespace
} // namespace Config
} // namespace Envoy

0 comments on commit 4769552

Please sign in to comment.