Skip to content

Commit

Permalink
Add mock address resolver to test
Browse files Browse the repository at this point in the history
Signed-off-by: Henna Huang <[email protected]>
  • Loading branch information
hennna committed Apr 11, 2018
1 parent 35116f8 commit b6cce92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,22 @@ 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",
"//source/common/network:socket_option_lib",
"//source/common/network:utility_lib",
"//source/extensions/filters/listener/original_dst:config",
"//source/extensions/transport_sockets/raw_buffer:config",
"//source/extensions/transport_sockets/ssl:config",
"//source/server:listener_manager_lib",
"//source/server/config/network:http_connection_manager_lib",
"//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
21 changes: 20 additions & 1 deletion test/server/listener_manager_impl_test.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#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 @@ -6,6 +8,7 @@
#include "common/network/address_impl.h"
#include "common/network/listen_socket_impl.h"
#include "common/network/socket_option_impl.h"
#include "common/network/utility.h"

#include "server/configuration_impl.h"
#include "server/listener_manager_impl.h"
Expand All @@ -15,6 +18,7 @@
#include "test/mocks/server/mocks.h"
#include "test/server/utility.h"
#include "test/test_common/environment.h"
#include "test/test_common/registry.h"
#include "test/test_common/threadsafe_singleton_injector.h"
#include "test/test_common/utility.h"

Expand Down Expand Up @@ -123,6 +127,13 @@ 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 @@ -1518,12 +1529,20 @@ TEST_F(ListenerManagerImplWithRealFiltersTest, AddressResolver) {
const std::string yaml = TestEnvironment::substitute(R"EOF(
name: AddressResolverdListener
address:
socket_address: { address: 127.0.0.1, port_value: 1111, resolver_name: envoy.ip }
socket_address: { address: 127.0.0.1, port_value: 1111, resolver_name: envoy.mock.resolver }
filter_chains:
- filters:
)EOF",
Network::Address::IpVersion::v4);

MockAddressResolver mock_resolver;
EXPECT_CALL(mock_resolver, name()).WillRepeatedly(Return("envoy.mock.resolver"));

EXPECT_CALL(mock_resolver, resolve(_))
.WillOnce(Return(Network::Utility::parseInternetAddress("127.0.0.1", 1111, false)));

Registry::InjectFactory<Network::Address::Resolver> register_resolver(mock_resolver);

EXPECT_CALL(listener_factory_, createListenSocket(_, _, true));
manager_->addOrUpdateListener(parseListenerFromV2Yaml(yaml), true);
EXPECT_EQ(1U, manager_->listeners().size());
Expand Down

0 comments on commit b6cce92

Please sign in to comment.