From 476955241945e54ad1555b1f22bfddea140898b2 Mon Sep 17 00:00:00 2001 From: yanavlasov Date: Tue, 30 Apr 2019 23:28:07 -0400 Subject: [PATCH] Add test of parsing weighted_cluster route configuration to improve test coverage. (#6711) Signed-off-by: Yan Avlasov --- test/common/config/rds_json_test.cc | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/common/config/rds_json_test.cc b/test/common/config/rds_json_test.cc index 17cd764787ee..5a6d57547398 100644 --- a/test/common/config/rds_json_test.cc +++ b/test/common/config/rds_json_test.cc @@ -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