Skip to content

Commit

Permalink
V2 v3 fragment change for router directory (envoyproxy#11973)
Browse files Browse the repository at this point in the history
V2 to V3 changes related to test/commom/router/ directory.

Risk Level: Low
Testing: unit, integration and format testing
Docs Changes: NA

Relates to envoyproxy#10843 

Signed-off-by: Abhay Narayan Katare <abhay.katare@india.nec.com>
Signed-off-by: scheler <santosh.cheler@appdynamics.com>
  • Loading branch information
ankatare authored and scheler committed Aug 4, 2020
1 parent aaa008e commit 2d609eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
21 changes: 11 additions & 10 deletions test/common/router/header_formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ namespace Envoy {
namespace Router {
namespace {

static envoy::config::route::v3::Route parseRouteFromV2Yaml(const std::string& yaml) {
static envoy::config::route::v3::Route parseRouteFromV3Yaml(const std::string& yaml,
bool avoid_boosting = true) {
envoy::config::route::v3::Route route;
TestUtility::loadFromYaml(yaml, route);
TestUtility::loadFromYaml(yaml, route, false, avoid_boosting);
return route;
}

Expand Down Expand Up @@ -931,7 +932,7 @@ match: { prefix: "/new_endpoint" }
)EOF";

HeaderParserPtr req_header_parser =
HeaderParser::configure(parseRouteFromV2Yaml(ymal).request_headers_to_add());
HeaderParser::configure(parseRouteFromV3Yaml(ymal).request_headers_to_add());
Http::TestRequestHeaderMapImpl header_map{{":method", "POST"}};
NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info;
req_header_parser->evaluateHeaders(header_map, stream_info);
Expand All @@ -953,7 +954,7 @@ match: { prefix: "/new_endpoint" }
)EOF";

HeaderParserPtr req_header_parser =
HeaderParser::configure(parseRouteFromV2Yaml(ymal).request_headers_to_add());
HeaderParser::configure(parseRouteFromV3Yaml(ymal).request_headers_to_add());
Http::TestRequestHeaderMapImpl header_map{{":method", "POST"}};
std::shared_ptr<NiceMock<Envoy::Upstream::MockHostDescription>> host(
new NiceMock<Envoy::Upstream::MockHostDescription>());
Expand All @@ -979,7 +980,7 @@ match: { prefix: "/new_endpoint" }
)EOF";

HeaderParserPtr req_header_parser =
HeaderParser::configure(parseRouteFromV2Yaml(ymal).request_headers_to_add());
HeaderParser::configure(parseRouteFromV3Yaml(ymal).request_headers_to_add());
Http::TestRequestHeaderMapImpl header_map{{":method", "POST"}};
NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info;
req_header_parser->evaluateHeaders(header_map, stream_info);
Expand Down Expand Up @@ -1023,7 +1024,7 @@ match: { prefix: "/new_endpoint" }
request_headers_to_remove: ["x-nope"]
)EOF";

const auto route = parseRouteFromV2Yaml(yaml);
const auto route = parseRouteFromV3Yaml(yaml);
HeaderParserPtr req_header_parser =
HeaderParser::configure(route.request_headers_to_add(), route.request_headers_to_remove());
Http::TestRequestHeaderMapImpl header_map{
Expand Down Expand Up @@ -1118,7 +1119,7 @@ match: { prefix: "/new_endpoint" }
)EOF";

// Disable append mode.
envoy::config::route::v3::Route route = parseRouteFromV2Yaml(ymal);
envoy::config::route::v3::Route route = parseRouteFromV3Yaml(ymal);
route.mutable_request_headers_to_add(0)->mutable_append()->set_value(false);
route.mutable_request_headers_to_add(1)->mutable_append()->set_value(false);
route.mutable_request_headers_to_add(2)->mutable_append()->set_value(false);
Expand Down Expand Up @@ -1211,7 +1212,7 @@ match: { prefix: "/new_endpoint" }
response_headers_to_remove: ["x-nope"]
)EOF";

const auto route = parseRouteFromV2Yaml(yaml);
const auto route = parseRouteFromV3Yaml(yaml);
HeaderParserPtr resp_header_parser =
HeaderParser::configure(route.response_headers_to_add(), route.response_headers_to_remove());
Http::TestRequestHeaderMapImpl header_map{
Expand Down Expand Up @@ -1262,7 +1263,7 @@ match: { prefix: "/new_endpoint" }
request_headers_to_remove: ["x-foo-header"]
)EOF";

const auto route = parseRouteFromV2Yaml(yaml);
const auto route = parseRouteFromV3Yaml(yaml);
HeaderParserPtr req_header_parser =
HeaderParser::configure(route.request_headers_to_add(), route.request_headers_to_remove());
Http::TestRequestHeaderMapImpl header_map{{"x-foo-header", "foo"}};
Expand All @@ -1284,7 +1285,7 @@ match: { prefix: "/new_endpoint" }
response_headers_to_remove: ["x-foo-header"]
)EOF";

const auto route = parseRouteFromV2Yaml(yaml);
const auto route = parseRouteFromV3Yaml(yaml);
HeaderParserPtr resp_header_parser =
HeaderParser::configure(route.response_headers_to_add(), route.response_headers_to_remove());
Http::TestResponseHeaderMapImpl header_map{{"x-foo-header", "foo"}};
Expand Down
18 changes: 9 additions & 9 deletions test/common/router/rds_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ class RouteConfigProviderManagerImplTest : public RdsTestBase {
};

envoy::config::route::v3::RouteConfiguration
parseRouteConfigurationFromV2Yaml(const std::string& yaml) {
parseRouteConfigurationFromV3Yaml(const std::string& yaml, bool avoid_boosting = true) {
envoy::config::route::v3::RouteConfiguration route_config;
TestUtility::loadFromYaml(yaml, route_config, true);
TestUtility::loadFromYaml(yaml, route_config, true, avoid_boosting);
return route_config;
}

Expand Down Expand Up @@ -394,7 +394,7 @@ name: foo
// Only static route.
RouteConfigProviderPtr static_config =
route_config_provider_manager_->createStaticRouteConfigProvider(
parseRouteConfigurationFromV2Yaml(config_yaml), server_factory_context_,
parseRouteConfigurationFromV3Yaml(config_yaml), server_factory_context_,
validation_visitor_);
message_ptr =
server_factory_context_.admin_.config_tracker_.config_tracker_callbacks_["routes"]();
Expand All @@ -403,7 +403,7 @@ name: foo
TestUtility::loadFromYaml(R"EOF(
static_route_configs:
- route_config:
"@type": type.googleapis.com/envoy.api.v2.RouteConfiguration
"@type": type.googleapis.com/envoy.config.route.v3.RouteConfiguration
name: foo
virtual_hosts:
- name: bar
Expand All @@ -430,7 +430,7 @@ name: foo
"version_info": "1",
"resources": [
{
"@type": "type.googleapis.com/envoy.api.v2.RouteConfiguration",
"@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"name": "foo_route_config",
"virtual_hosts": null
}
Expand All @@ -451,7 +451,7 @@ name: foo
TestUtility::loadFromYaml(R"EOF(
static_route_configs:
- route_config:
"@type": type.googleapis.com/envoy.api.v2.RouteConfiguration
"@type": type.googleapis.com/envoy.config.route.v3.RouteConfiguration
name: foo
virtual_hosts:
- name: bar
Expand All @@ -465,7 +465,7 @@ name: foo
dynamic_route_configs:
- version_info: "1"
route_config:
"@type": type.googleapis.com/envoy.api.v2.RouteConfiguration
"@type": type.googleapis.com/envoy.config.route.v3.RouteConfiguration
name: foo_route_config
virtual_hosts:
last_updated:
Expand All @@ -484,7 +484,7 @@ TEST_F(RouteConfigProviderManagerImplTest, Basic) {

EXPECT_FALSE(provider_->configInfo().has_value());

const auto route_config = parseRouteConfigurationFromV2Yaml(R"EOF(
const auto route_config = parseRouteConfigurationFromV3Yaml(R"EOF(
name: foo_route_config
virtual_hosts:
- name: bar
Expand Down Expand Up @@ -565,7 +565,7 @@ TEST_F(RouteConfigProviderManagerImplTest, SameProviderOnTwoInitManager) {
EXPECT_EQ(Init::Manager::State::Initializing, real_init_manager.state());

{
const auto route_config = parseRouteConfigurationFromV2Yaml(R"EOF(
const auto route_config = parseRouteConfigurationFromV3Yaml(R"EOF(
name: foo_route_config
virtual_hosts:
- name: bar
Expand Down
15 changes: 8 additions & 7 deletions test/common/router/router_ratelimit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ namespace Envoy {
namespace Router {
namespace {

envoy::config::route::v3::RateLimit parseRateLimitFromV2Yaml(const std::string& yaml_string) {
envoy::config::route::v3::RateLimit parseRateLimitFromV3Yaml(const std::string& yaml_string,
bool avoid_boosting = true) {
envoy::config::route::v3::RateLimit rate_limit;
TestUtility::loadFromYaml(yaml_string, rate_limit);
TestUtility::loadFromYaml(yaml_string, rate_limit, false, avoid_boosting);
TestUtility::validate(rate_limit);
return rate_limit;
}

TEST(BadRateLimitConfiguration, MissingActions) {
EXPECT_THROW_WITH_REGEX(parseRateLimitFromV2Yaml("{}"), EnvoyException,
EXPECT_THROW_WITH_REGEX(parseRateLimitFromV3Yaml("{}"), EnvoyException,
"value must contain at least");
}

Expand All @@ -46,7 +47,7 @@ TEST(BadRateLimitConfiguration, ActionsMissingRequiredFields) {
- request_headers: {}
)EOF";

EXPECT_THROW_WITH_REGEX(parseRateLimitFromV2Yaml(yaml_one), EnvoyException,
EXPECT_THROW_WITH_REGEX(parseRateLimitFromV3Yaml(yaml_one), EnvoyException,
"value length must be at least");

const std::string yaml_two = R"EOF(
Expand All @@ -55,7 +56,7 @@ TEST(BadRateLimitConfiguration, ActionsMissingRequiredFields) {
header_name: test
)EOF";

EXPECT_THROW_WITH_REGEX(parseRateLimitFromV2Yaml(yaml_two), EnvoyException,
EXPECT_THROW_WITH_REGEX(parseRateLimitFromV3Yaml(yaml_two), EnvoyException,
"value length must be at least");

const std::string yaml_three = R"EOF(
Expand All @@ -64,7 +65,7 @@ TEST(BadRateLimitConfiguration, ActionsMissingRequiredFields) {
descriptor_key: test
)EOF";

EXPECT_THROW_WITH_REGEX(parseRateLimitFromV2Yaml(yaml_three), EnvoyException,
EXPECT_THROW_WITH_REGEX(parseRateLimitFromV3Yaml(yaml_three), EnvoyException,
"value length must be at least");
}

Expand Down Expand Up @@ -268,7 +269,7 @@ TEST_F(RateLimitConfiguration, Stages) {
class RateLimitPolicyEntryTest : public testing::Test {
public:
void setupTest(const std::string& yaml) {
rate_limit_entry_ = std::make_unique<RateLimitPolicyEntryImpl>(parseRateLimitFromV2Yaml(yaml));
rate_limit_entry_ = std::make_unique<RateLimitPolicyEntryImpl>(parseRateLimitFromV3Yaml(yaml));
descriptors_.clear();
}

Expand Down

0 comments on commit 2d609eb

Please sign in to comment.