Skip to content

Commit

Permalink
Move mock resolver to test/mocks/network/...
Browse files Browse the repository at this point in the history
Signed-off-by: Henna Huang <[email protected]>
  • Loading branch information
hennna committed Apr 12, 2018
1 parent b6cce92 commit b51a2ec
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions test/mocks/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
6 changes: 6 additions & 0 deletions test/mocks/network/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_));
Expand Down
12 changes: 12 additions & 0 deletions test/mocks/network/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <list>
#include <string>

#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"
Expand Down Expand Up @@ -147,6 +149,16 @@ class MockDnsResolver : public DnsResolver {
testing::NiceMock<MockActiveDnsQuery> 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();
Expand Down
3 changes: 1 addition & 2 deletions test/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
)

Expand Down
14 changes: 2 additions & 12 deletions test/server/listener_manager_impl_test.cc
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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<Network::MockAddressResolver> mock_resolver;
EXPECT_CALL(mock_resolver, resolve(_))
.WillOnce(Return(Network::Utility::parseInternetAddress("127.0.0.1", 1111, false)));

Expand Down

0 comments on commit b51a2ec

Please sign in to comment.