From b51a2ec093adf9134b7ae5331a858d91ad879078 Mon Sep 17 00:00:00 2001 From: Henna Huang Date: Thu, 12 Apr 2018 01:24:14 -0400 Subject: [PATCH] Move mock resolver to test/mocks/network/... Signed-off-by: Henna Huang --- test/mocks/network/BUILD | 2 ++ test/mocks/network/mocks.cc | 6 ++++++ test/mocks/network/mocks.h | 12 ++++++++++++ test/server/BUILD | 3 +-- test/server/listener_manager_impl_test.cc | 14 ++------------ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/test/mocks/network/BUILD b/test/mocks/network/BUILD index 5cc4100695b2..1ad8b522255c 100644 --- a/test/mocks/network/BUILD +++ b/test/mocks/network/BUILD @@ -17,10 +17,12 @@ envoy_cc_mock( "//include/envoy/network:connection_interface", "//include/envoy/network:drain_decision_interface", "//include/envoy/network:filter_interface", + "//include/envoy/network:resolver_interface", "//include/envoy/network:transport_socket_interface", "//include/envoy/server:listener_manager_interface", "//source/common/network:address_lib", "//source/common/network:utility_lib", "//test/mocks/event:event_mocks", + "@envoy_api//envoy/api/v2/core:base_cc", ], ) diff --git a/test/mocks/network/mocks.cc b/test/mocks/network/mocks.cc index 92ddb0bd3937..5930dae472c8 100644 --- a/test/mocks/network/mocks.cc +++ b/test/mocks/network/mocks.cc @@ -117,6 +117,12 @@ MockDnsResolver::MockDnsResolver() { MockDnsResolver::~MockDnsResolver() {} +MockAddressResolver::MockAddressResolver() { + ON_CALL(*this, name()).WillByDefault(Return("envoy.mock.resolver")); +} + +MockAddressResolver::~MockAddressResolver() {} + MockReadFilterCallbacks::MockReadFilterCallbacks() { ON_CALL(*this, connection()).WillByDefault(ReturnRef(connection_)); ON_CALL(*this, upstreamHost()).WillByDefault(ReturnPointee(&host_)); diff --git a/test/mocks/network/mocks.h b/test/mocks/network/mocks.h index 9b0d70ed699e..4037bd7ffa14 100644 --- a/test/mocks/network/mocks.h +++ b/test/mocks/network/mocks.h @@ -4,9 +4,11 @@ #include #include +#include "envoy/api/v2/core/address.pb.h" #include "envoy/network/connection.h" #include "envoy/network/drain_decision.h" #include "envoy/network/filter.h" +#include "envoy/network/resolver.h" #include "envoy/network/transport_socket.h" #include "common/stats/stats_impl.h" @@ -147,6 +149,16 @@ class MockDnsResolver : public DnsResolver { testing::NiceMock active_query_; }; +class MockAddressResolver : public Address::Resolver { +public: + MockAddressResolver(); + ~MockAddressResolver(); + + MOCK_METHOD1(resolve, + Address::InstanceConstSharedPtr(const envoy::api::v2::core::SocketAddress&)); + MOCK_CONST_METHOD0(name, std::string()); +}; + class MockReadFilterCallbacks : public ReadFilterCallbacks { public: MockReadFilterCallbacks(); diff --git a/test/server/BUILD b/test/server/BUILD index 98a38609719c..77c324dbe0e7 100644 --- a/test/server/BUILD +++ b/test/server/BUILD @@ -128,7 +128,6 @@ envoy_cc_test( data = ["//test/common/ssl/test_data:certs"], deps = [ ":utility_lib", - "//include/envoy/network:resolver_interface", "//source/common/api:os_sys_calls_lib", "//source/common/config:metadata_lib", "//source/common/network:listen_socket_lib", @@ -139,11 +138,11 @@ envoy_cc_test( "//source/extensions/transport_sockets/ssl:config", "//source/server:listener_manager_lib", "//source/server/config/network:http_connection_manager_lib", + "//test/mocks/network:network_mocks", "//test/mocks/server:server_mocks", "//test/test_common:environment_lib", "//test/test_common:registry_lib", "//test/test_common:threadsafe_singleton_injector_lib", - "@envoy_api//envoy/api/v2/core:base_cc", ], ) diff --git a/test/server/listener_manager_impl_test.cc b/test/server/listener_manager_impl_test.cc index ada710645242..bf71d137ff88 100644 --- a/test/server/listener_manager_impl_test.cc +++ b/test/server/listener_manager_impl_test.cc @@ -1,5 +1,3 @@ -#include "envoy/api/v2/core/address.pb.h" -#include "envoy/network/resolver.h" #include "envoy/registry/registry.h" #include "envoy/server/filter_config.h" @@ -15,6 +13,7 @@ #include "extensions/filters/listener/original_dst/original_dst.h" +#include "test/mocks/network/mocks.h" #include "test/mocks/server/mocks.h" #include "test/server/utility.h" #include "test/test_common/environment.h" @@ -127,13 +126,6 @@ class ListenerManagerImplWithRealFiltersTest : public ListenerManagerImplTest { } }; -class MockAddressResolver : public Network::Address::Resolver { -public: - MOCK_METHOD1(resolve, Network::Address::InstanceConstSharedPtr( - const envoy::api::v2::core::SocketAddress&)); - MOCK_CONST_METHOD0(name, std::string()); -}; - TEST_F(ListenerManagerImplWithRealFiltersTest, EmptyFilter) { const std::string json = R"EOF( { @@ -1535,9 +1527,7 @@ TEST_F(ListenerManagerImplWithRealFiltersTest, AddressResolver) { )EOF", Network::Address::IpVersion::v4); - MockAddressResolver mock_resolver; - EXPECT_CALL(mock_resolver, name()).WillRepeatedly(Return("envoy.mock.resolver")); - + NiceMock mock_resolver; EXPECT_CALL(mock_resolver, resolve(_)) .WillOnce(Return(Network::Utility::parseInternetAddress("127.0.0.1", 1111, false)));