Skip to content

Commit

Permalink
V2 TO V3 fragment changes for extension and server directory under te…
Browse files Browse the repository at this point in the history
…st/.. (envoyproxy#12058)

Commit Message: v2 to v3 fragment changes for extension and server directory test cases.
Risk Level: Low
Testing: unit and format
Fixes envoyproxy#10843

Signed-off-by: Abhay Narayan Katare <[email protected]>
Signed-off-by: chaoqinli <[email protected]>
  • Loading branch information
ankatare authored and chaoqinli committed Aug 7, 2020
1 parent ac986fe commit 1548eb0
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 272 deletions.
11 changes: 6 additions & 5 deletions test/extensions/clusters/redis/redis_cluster_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ class RedisClusterTest : public testing::Test,
return addresses;
}

void setupFromV3Yaml(const std::string& yaml) {
void setupFromV3Yaml(const std::string& yaml, bool avoid_boosting = true) {
expectRedisSessionCreated();
NiceMock<Upstream::MockClusterManager> cm;
envoy::config::cluster::v3::Cluster cluster_config = Upstream::parseClusterFromV3Yaml(yaml);
envoy::config::cluster::v3::Cluster cluster_config =
Upstream::parseClusterFromV3Yaml(yaml, avoid_boosting);
Envoy::Stats::ScopePtr scope = stats_store_.createScope(fmt::format(
"cluster.{}.", cluster_config.alt_stat_name().empty() ? cluster_config.name()
: cluster_config.alt_stat_name()));
Expand Down Expand Up @@ -121,7 +122,7 @@ class RedisClusterTest : public testing::Test,
});
}

void setupFactoryFromV2Yaml(const std::string& yaml) {
void setupFactoryFromV3Yaml(const std::string& yaml) {
NiceMock<Upstream::MockClusterManager> cm;
envoy::config::cluster::v3::Cluster cluster_config = Upstream::parseClusterFromV3Yaml(yaml);
Envoy::Stats::ScopePtr scope = stats_store_.createScope(fmt::format(
Expand Down Expand Up @@ -793,12 +794,12 @@ TEST_F(RedisClusterTest, FactoryInitNotRedisClusterTypeFailure) {
cluster_refresh_timeout: 0.25s
)EOF";

EXPECT_THROW_WITH_MESSAGE(setupFactoryFromV2Yaml(basic_yaml_hosts), EnvoyException,
EXPECT_THROW_WITH_MESSAGE(setupFactoryFromV3Yaml(basic_yaml_hosts), EnvoyException,
"Redis cluster can only created with redis cluster type.");
}

TEST_F(RedisClusterTest, FactoryInitRedisClusterTypeSuccess) {
setupFactoryFromV2Yaml(BasicConfig);
setupFactoryFromV3Yaml(BasicConfig);
}

TEST_F(RedisClusterTest, RedisErrorResponse) {
Expand Down
8 changes: 4 additions & 4 deletions test/extensions/filters/http/router/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST(RouterFilterConfigTest, SimpleRouterFilterConfig) {
)EOF";

envoy::extensions::filters::http::router::v3::Router proto_config;
TestUtility::loadFromYaml(yaml_string, proto_config);
TestUtility::loadFromYaml(yaml_string, proto_config, false, true);
NiceMock<Server::Configuration::MockFactoryContext> context;
RouterFilterConfig factory;
Http::FilterFactoryCb cb = factory.createFilterFactoryFromProto(proto_config, "stats.", context);
Expand All @@ -43,8 +43,8 @@ TEST(RouterFilterConfigTest, BadRouterFilterConfig) {
)EOF";

envoy::extensions::filters::http::router::v3::Router proto_config;
EXPECT_THROW_WITH_REGEX(TestUtility::loadFromYaml(yaml_string, proto_config), EnvoyException,
"route: Cannot find field");
EXPECT_THROW_WITH_REGEX(TestUtility::loadFromYaml(yaml_string, proto_config, false, true),
EnvoyException, "route: Cannot find field");
}

TEST(RouterFilterConfigTest, RouterFilterWithUnsupportedStrictHeaderCheck) {
Expand All @@ -54,7 +54,7 @@ TEST(RouterFilterConfigTest, RouterFilterWithUnsupportedStrictHeaderCheck) {
)EOF";

envoy::extensions::filters::http::router::v3::Router router_config;
TestUtility::loadFromYaml(yaml, router_config);
TestUtility::loadFromYaml(yaml, router_config, false, true);

NiceMock<Server::Configuration::MockFactoryContext> context;
RouterFilterConfig factory;
Expand Down
12 changes: 6 additions & 6 deletions test/extensions/filters/network/dubbo_proxy/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ using DubboProxyProto = envoy::extensions::filters::network::dubbo_proxy::v3::Du

namespace {

DubboProxyProto parseDubboProxyFromV2Yaml(const std::string& yaml) {
DubboProxyProto parseDubboProxyFromV3Yaml(const std::string& yaml, bool avoid_boosting = true) {
DubboProxyProto dubbo_proxy;
TestUtility::loadFromYaml(yaml, dubbo_proxy);
TestUtility::loadFromYaml(yaml, dubbo_proxy, false, avoid_boosting);
return dubbo_proxy;
}

Expand Down Expand Up @@ -92,7 +92,7 @@ TEST_F(DubboFilterConfigTest, DubboProxyWithExplicitRouterConfig) {
- name: envoy.filters.dubbo.router
)EOF";

DubboProxyProto config = parseDubboProxyFromV2Yaml(yaml);
DubboProxyProto config = parseDubboProxyFromV3Yaml(yaml);
testConfig(config);
}

Expand All @@ -107,7 +107,7 @@ TEST_F(DubboFilterConfigTest, DubboProxyWithUnknownFilter) {
- name: envoy.filters.dubbo.router
)EOF";

DubboProxyProto config = parseDubboProxyFromV2Yaml(yaml);
DubboProxyProto config = parseDubboProxyFromV3Yaml(yaml);

EXPECT_THROW_WITH_REGEX(factory_.createFilterFactoryFromProto(config, context_), EnvoyException,
"no_such_filter");
Expand All @@ -131,7 +131,7 @@ TEST_F(DubboFilterConfigTest, DubboProxyWithMultipleFilters) {
DubboFilters::MockFilterConfigFactory factory;
Registry::InjectFactory<DubboFilters::NamedDubboFilterConfigFactory> registry(factory);

DubboProxyProto config = parseDubboProxyFromV2Yaml(yaml);
DubboProxyProto config = parseDubboProxyFromV3Yaml(yaml);
testConfig(config);

EXPECT_EQ(1, factory.config_struct_.fields_size());
Expand All @@ -156,7 +156,7 @@ TEST_F(DubboFilterConfigTest, CreateFilterChain) {
DubboFilters::MockFilterConfigFactory factory;
Registry::InjectFactory<DubboFilters::NamedDubboFilterConfigFactory> registry(factory);

DubboProxyProto dubbo_config = parseDubboProxyFromV2Yaml(yaml);
DubboProxyProto dubbo_config = parseDubboProxyFromV3Yaml(yaml);

NiceMock<Server::Configuration::MockFactoryContext> context;
DubboFilters::MockFilterChainFactoryCallbacks callbacks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RateLimitFilterTest : public testing::Test {
.WillByDefault(Return(true));

envoy::extensions::filters::network::ratelimit::v3::RateLimit proto_config{};
TestUtility::loadFromYaml(yaml, proto_config);
TestUtility::loadFromYaml(yaml, proto_config, false, true);
config_ = std::make_shared<Config>(proto_config, stats_store_, runtime_);
client_ = new Filters::Common::RateLimit::MockClient();
filter_ = std::make_unique<Filter>(config_, Filters::Common::RateLimit::ClientPtr{client_});
Expand Down
9 changes: 5 additions & 4 deletions test/extensions/filters/network/rocketmq_proxy/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ namespace RocketmqProxy {

using RocketmqProxyProto = envoy::extensions::filters::network::rocketmq_proxy::v3::RocketmqProxy;

RocketmqProxyProto parseRocketmqProxyFromV2Yaml(const std::string& yaml) {
RocketmqProxyProto parseRocketmqProxyFromV3Yaml(const std::string& yaml,
bool avoid_boosting = true) {
RocketmqProxyProto rocketmq_proxy;
TestUtility::loadFromYaml(yaml, rocketmq_proxy);
TestUtility::loadFromYaml(yaml, rocketmq_proxy, false, avoid_boosting);
return rocketmq_proxy;
}

Expand Down Expand Up @@ -86,7 +87,7 @@ TEST_F(RocketmqFilterConfigTest, RocketmqProxyWithFullConfig) {
transient_object_life_span:
seconds: 30
)EOF";
RocketmqProxyProto config = parseRocketmqProxyFromV2Yaml(yaml);
RocketmqProxyProto config = parseRocketmqProxyFromV3Yaml(yaml);
testConfig(config);
}

Expand Down Expand Up @@ -168,4 +169,4 @@ TEST_F(RocketmqFilterConfigTest, ProxyAddressWithNonIpType) {
} // namespace RocketmqProxy
} // namespace NetworkFilters
} // namespace Extensions
} // namespace Envoy
} // namespace Envoy
2 changes: 1 addition & 1 deletion test/extensions/filters/network/tcp_proxy/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST_P(RouteIpListConfigTest, DEPRECATED_FEATURE_TEST(TcpProxy)) {
)EOF";

envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy proto_config;
TestUtility::loadFromJson(json_string, proto_config, true);
TestUtility::loadFromJson(json_string, proto_config, true, false);

NiceMock<Server::Configuration::MockFactoryContext> context;
ConfigFactory factory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace RateLimitFilter {
namespace {

envoy::extensions::filters::network::thrift_proxy::filters::ratelimit::v3::RateLimit
parseRateLimitFromV2Yaml(const std::string& yaml) {
parseRateLimitFromV3Yaml(const std::string& yaml, bool avoid_boosting = true) {
envoy::extensions::filters::network::thrift_proxy::filters::ratelimit::v3::RateLimit rate_limit;
TestUtility::loadFromYaml(yaml, rate_limit);
TestUtility::loadFromYaml(yaml, rate_limit, false, avoid_boosting);
return rate_limit;
}

Expand All @@ -46,7 +46,7 @@ timeout: "1.337s"
cluster_name: ratelimit_cluster
)EOF";

auto proto_config = parseRateLimitFromV2Yaml(yaml_string);
auto proto_config = parseRateLimitFromV3Yaml(yaml_string);

NiceMock<Server::Configuration::MockFactoryContext> context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class ThriftRateLimitFilterTest : public testing::Test {
.WillByDefault(Return(true));
}

void SetUpTest(const std::string& yaml) {
void setupTest(const std::string& yaml) {
envoy::extensions::filters::network::thrift_proxy::filters::ratelimit::v3::RateLimit
proto_config{};
TestUtility::loadFromYaml(yaml, proto_config);
TestUtility::loadFromYaml(yaml, proto_config, false, true);

config_ = std::make_shared<Config>(proto_config, local_info_, stats_store_, runtime_, cm_);

Expand Down Expand Up @@ -94,7 +94,7 @@ class ThriftRateLimitFilterTest : public testing::Test {
};

TEST_F(ThriftRateLimitFilterTest, NoRoute) {
SetUpTest(filter_config_);
setupTest(filter_config_);

EXPECT_CALL(*filter_callbacks_.route_, routeEntry()).WillOnce(Return(nullptr));

Expand Down Expand Up @@ -165,15 +165,15 @@ TEST_F(ThriftRateLimitFilterTest, NoRoute) {
}

TEST_F(ThriftRateLimitFilterTest, NoCluster) {
SetUpTest(filter_config_);
setupTest(filter_config_);

ON_CALL(cm_, get(_)).WillByDefault(Return(nullptr));

EXPECT_EQ(ThriftProxy::FilterStatus::Continue, filter_->messageBegin(request_metadata_));
}

TEST_F(ThriftRateLimitFilterTest, NoApplicableRateLimit) {
SetUpTest(filter_config_);
setupTest(filter_config_);

filter_callbacks_.route_->route_entry_.rate_limit_policy_.rate_limit_policy_entry_.clear();
EXPECT_CALL(*client_, limit(_, _, _, _)).Times(0);
Expand All @@ -182,7 +182,7 @@ TEST_F(ThriftRateLimitFilterTest, NoApplicableRateLimit) {
}

TEST_F(ThriftRateLimitFilterTest, NoDescriptor) {
SetUpTest(filter_config_);
setupTest(filter_config_);

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _)).Times(1);
EXPECT_CALL(*client_, limit(_, _, _, _)).Times(0);
Expand All @@ -191,7 +191,7 @@ TEST_F(ThriftRateLimitFilterTest, NoDescriptor) {
}

TEST_F(ThriftRateLimitFilterTest, RuntimeDisabled) {
SetUpTest(filter_config_);
setupTest(filter_config_);

EXPECT_CALL(runtime_.snapshot_, featureEnabled("ratelimit.thrift_filter_enabled", 100))
.WillOnce(Return(false));
Expand All @@ -200,7 +200,7 @@ TEST_F(ThriftRateLimitFilterTest, RuntimeDisabled) {
}

TEST_F(ThriftRateLimitFilterTest, OkResponse) {
SetUpTest(filter_config_);
setupTest(filter_config_);
InSequence s;

EXPECT_CALL(filter_callbacks_.route_->route_entry_.rate_limit_policy_, getApplicableRateLimit(0))
Expand Down Expand Up @@ -233,7 +233,7 @@ TEST_F(ThriftRateLimitFilterTest, OkResponse) {
}

TEST_F(ThriftRateLimitFilterTest, ImmediateOkResponse) {
SetUpTest(filter_config_);
setupTest(filter_config_);
InSequence s;

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _))
Expand All @@ -256,7 +256,7 @@ TEST_F(ThriftRateLimitFilterTest, ImmediateOkResponse) {
}

TEST_F(ThriftRateLimitFilterTest, ImmediateErrorResponse) {
SetUpTest(filter_config_);
setupTest(filter_config_);
InSequence s;

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _))
Expand All @@ -283,7 +283,7 @@ TEST_F(ThriftRateLimitFilterTest, ImmediateErrorResponse) {
}

TEST_F(ThriftRateLimitFilterTest, ErrorResponse) {
SetUpTest(filter_config_);
setupTest(filter_config_);
InSequence s;

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _))
Expand Down Expand Up @@ -313,7 +313,7 @@ TEST_F(ThriftRateLimitFilterTest, ErrorResponse) {
}

TEST_F(ThriftRateLimitFilterTest, ErrorResponseWithFailureModeAllowOff) {
SetUpTest(fail_close_config_);
setupTest(fail_close_config_);
InSequence s;

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _))
Expand Down Expand Up @@ -345,7 +345,7 @@ TEST_F(ThriftRateLimitFilterTest, ErrorResponseWithFailureModeAllowOff) {
}

TEST_F(ThriftRateLimitFilterTest, LimitResponse) {
SetUpTest(filter_config_);
setupTest(filter_config_);
InSequence s;

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _))
Expand Down Expand Up @@ -376,7 +376,7 @@ TEST_F(ThriftRateLimitFilterTest, LimitResponse) {
}

TEST_F(ThriftRateLimitFilterTest, LimitResponseWithHeaders) {
SetUpTest(filter_config_);
setupTest(filter_config_);
InSequence s;

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _))
Expand Down Expand Up @@ -409,7 +409,7 @@ TEST_F(ThriftRateLimitFilterTest, LimitResponseWithHeaders) {
}

TEST_F(ThriftRateLimitFilterTest, LimitResponseRuntimeDisabled) {
SetUpTest(filter_config_);
setupTest(filter_config_);
InSequence s;

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _))
Expand All @@ -434,7 +434,7 @@ TEST_F(ThriftRateLimitFilterTest, LimitResponseRuntimeDisabled) {
}

TEST_F(ThriftRateLimitFilterTest, ResetDuringCall) {
SetUpTest(filter_config_);
setupTest(filter_config_);
InSequence s;

EXPECT_CALL(route_rate_limit_, populateDescriptors(_, _, _, _, _))
Expand All @@ -453,7 +453,7 @@ TEST_F(ThriftRateLimitFilterTest, ResetDuringCall) {

TEST_F(ThriftRateLimitFilterTest, RouteRateLimitDisabledForRouteKey) {
route_rate_limit_.disable_key_ = "test_key";
SetUpTest(filter_config_);
setupTest(filter_config_);

ON_CALL(runtime_.snapshot_, featureEnabled("ratelimit.test_key.thrift_filter_enabled", 100))
.WillByDefault(Return(false));
Expand All @@ -472,7 +472,7 @@ TEST_F(ThriftRateLimitFilterTest, ConfigValueTest) {
}
)EOF";

SetUpTest(stage_filter_config);
setupTest(stage_filter_config);

EXPECT_EQ(5UL, config_->stage());
EXPECT_EQ("foo", config_->domain());
Expand All @@ -485,7 +485,7 @@ TEST_F(ThriftRateLimitFilterTest, DefaultConfigValueTest) {
}
)EOF";

SetUpTest(stage_filter_config);
setupTest(stage_filter_config);

EXPECT_EQ(0UL, config_->stage());
EXPECT_EQ("foo", config_->domain());
Expand Down
Loading

0 comments on commit 1548eb0

Please sign in to comment.