From 298918621514cd0b2dd4c2b597ced1c50d215c62 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 29 Jun 2020 04:47:03 +0000 Subject: [PATCH 01/17] added splitted up mock headers Signed-off-by: Muge Chen --- test/mocks/server/BUILD | 256 ++++++++++++++++++ test/mocks/server/admin_stream.cc | 25 ++ test/mocks/server/admin_stream.h | 32 +++ .../server/bootstrap_extension_factory.cc | 16 ++ .../server/bootstrap_extension_factory.h | 29 ++ test/mocks/server/drain_manager.cc | 27 ++ test/mocks/server/drain_manager.h | 28 ++ test/mocks/server/factory_context.cc | 56 ++++ test/mocks/server/factory_context.h | 83 ++++++ .../server/filter_chain_factory_context.cc | 28 ++ .../server/filter_chain_factory_context.h | 23 ++ test/mocks/server/guard_dog.cc | 28 ++ test/mocks/server/guard_dog.h | 25 ++ .../server/health_checker_factory_context.cc | 40 +++ .../server/health_checker_factory_context.h | 50 ++++ test/mocks/server/hot_restart.cc | 29 ++ test/mocks/server/hot_restart.h | 45 +++ test/mocks/server/instance.cc | 79 ++++++ test/mocks/server/instance.h | 177 ++++++++++++ .../server/listener_component_factory.cc | 40 +++ .../mocks/server/listener_component_factory.h | 53 ++++ test/mocks/server/listener_factory_context.cc | 26 ++ test/mocks/server/listener_factory_context.h | 30 ++ test/mocks/server/listener_manager.cc | 25 ++ test/mocks/server/listener_manager.h | 36 +++ test/mocks/server/main.cc | 35 +++ test/mocks/server/main.h | 39 +++ test/mocks/server/options.cc | 57 ++++ test/mocks/server/options.h | 82 ++++++ test/mocks/server/overload_manager.cc | 28 ++ test/mocks/server/overload_manager.h | 30 ++ .../mocks/server/server_lifecycle_notifier.cc | 25 ++ test/mocks/server/server_lifecycle_notifier.h | 26 ++ test/mocks/server/tracer_factory.cc | 32 +++ test/mocks/server/tracer_factory.h | 34 +++ test/mocks/server/tracer_factory_context.cc | 33 +++ test/mocks/server/tracer_factory_context.h | 80 ++++++ .../transport_socket_factory_context.cc | 36 +++ .../server/transport_socket_factory_context.h | 51 ++++ test/mocks/server/watch_dog.cc | 25 ++ test/mocks/server/watch_dog.h | 27 ++ test/mocks/server/worker.cc | 56 ++++ test/mocks/server/worker.h | 60 ++++ test/mocks/server/worker_factory.cc | 25 ++ test/mocks/server/worker_factory.h | 29 ++ 45 files changed, 2096 insertions(+) create mode 100644 test/mocks/server/admin_stream.cc create mode 100644 test/mocks/server/admin_stream.h create mode 100644 test/mocks/server/bootstrap_extension_factory.cc create mode 100644 test/mocks/server/bootstrap_extension_factory.h create mode 100644 test/mocks/server/drain_manager.cc create mode 100644 test/mocks/server/drain_manager.h create mode 100644 test/mocks/server/factory_context.cc create mode 100644 test/mocks/server/factory_context.h create mode 100644 test/mocks/server/filter_chain_factory_context.cc create mode 100644 test/mocks/server/filter_chain_factory_context.h create mode 100644 test/mocks/server/guard_dog.cc create mode 100644 test/mocks/server/guard_dog.h create mode 100644 test/mocks/server/health_checker_factory_context.cc create mode 100644 test/mocks/server/health_checker_factory_context.h create mode 100644 test/mocks/server/hot_restart.cc create mode 100644 test/mocks/server/hot_restart.h create mode 100644 test/mocks/server/instance.cc create mode 100644 test/mocks/server/instance.h create mode 100644 test/mocks/server/listener_component_factory.cc create mode 100644 test/mocks/server/listener_component_factory.h create mode 100644 test/mocks/server/listener_factory_context.cc create mode 100644 test/mocks/server/listener_factory_context.h create mode 100644 test/mocks/server/listener_manager.cc create mode 100644 test/mocks/server/listener_manager.h create mode 100644 test/mocks/server/main.cc create mode 100644 test/mocks/server/main.h create mode 100644 test/mocks/server/options.cc create mode 100644 test/mocks/server/options.h create mode 100644 test/mocks/server/overload_manager.cc create mode 100644 test/mocks/server/overload_manager.h create mode 100644 test/mocks/server/server_lifecycle_notifier.cc create mode 100644 test/mocks/server/server_lifecycle_notifier.h create mode 100644 test/mocks/server/tracer_factory.cc create mode 100644 test/mocks/server/tracer_factory.h create mode 100644 test/mocks/server/tracer_factory_context.cc create mode 100644 test/mocks/server/tracer_factory_context.h create mode 100644 test/mocks/server/transport_socket_factory_context.cc create mode 100644 test/mocks/server/transport_socket_factory_context.h create mode 100644 test/mocks/server/watch_dog.cc create mode 100644 test/mocks/server/watch_dog.h create mode 100644 test/mocks/server/worker.cc create mode 100644 test/mocks/server/worker.h create mode 100644 test/mocks/server/worker_factory.cc create mode 100644 test/mocks/server/worker_factory.h diff --git a/test/mocks/server/BUILD b/test/mocks/server/BUILD index a907ca21feb7..116a189bc1aa 100644 --- a/test/mocks/server/BUILD +++ b/test/mocks/server/BUILD @@ -27,6 +27,262 @@ envoy_cc_mock( ], ) + +envoy_cc_mock( + name = "bootstrap_extension_factory_mocks", + srcs = ["bootstrap_extension_factory.cc"], + hdrs = ["bootstrap_extension_factory.h"], + deps = [ + "//include/envoy/server:bootstrap_extension_config_interface", + ] +) + +envoy_cc_mock( + name = "options_mocks", + srcs = ["options.cc"], + hdrs = ["options.h"], + deps = [ + "//include/envoy/server:options_interface", + "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto", + "@envoy_api//envoy/admin/v3:pkg_cc_proto", + ] +) + +envoy_cc_mock( + name = "admin_stream_mocks", + srcs = ["admin_stream.cc"], + hdrs = ["admin_stream.h"], + deps = [ + "//include/envoy/server:admin_interface", + "//test/mocks/http:http_mocks", + ] +) + +envoy_cc_mock( + name = "drain_manager_mocks", + srcs = ["drain_manager.cc"], + hdrs = ["drain_manager.h"], + deps = [ + "//include/envoy/server:drain_manager_interface", + ] +) + +envoy_cc_mock( + name = "watch_dog_mocks", + srcs = ["watch_dog.cc"], + hdrs = ["watch_dog.h"], + deps = [ + "//include/envoy/server:watchdog_interface", + ] +) + +envoy_cc_mock( + name = "guard_dog_mocks", + srcs = ["guard_dog.cc"], + hdrs = ["guard_dog.h"], + deps = [ + "//include/envoy/server:guarddog_interface", + "//test/mocks/server:watch_dog_mocks", + ] +) + +envoy_cc_mock( + name = "hot_restart_mocks", + srcs = ["hot_restart.cc"], + hdrs = ["hot_restart.h"], + deps = [ + "//include/envoy/server:instance_interface", + "//test/mocks/stats:stats_mocks", + ] +) + +envoy_cc_mock( + name = "listener_component_factory_mocks", + srcs = ["listener_component_factory.cc"], + hdrs = ["listener_component_factory.h"], + deps = [ + "//include/envoy/server:listener_manager_interface", + "//include/envoy/server:drain_manager_interface", + "//test/mocks/network:network_mocks", + "@envoy_api//envoy/config/listener/v3:pkg_cc_proto", + "@envoy_api//envoy/config/core/v3:pkg_cc_proto", + ] +) + +envoy_cc_mock( + name = "listener_manager_mocks", + srcs = ["listener_manager.cc"], + hdrs = ["listener_manager.h"], + deps = [ + "//include/envoy/server:listener_manager_interface", + ] +) + +envoy_cc_mock( + name = "server_lifecycle_notifier_mocks", + srcs = ["server_lifecycle_notifier.cc"], + hdrs = ["server_lifecycle_notifier.h"], + deps = [ + "//include/envoy/server:lifecycle_notifier_interface", + ] +) + +envoy_cc_mock( + name = "worker_factory_mocks", + srcs = ["worker_factory.cc"], + hdrs = ["worker_factory.h"], + deps = [ + "//include/envoy/server:worker_interface", + "//test/mocks/server:worker_mocks", + ] +) + +envoy_cc_mock( + name = "worker_mocks", + srcs = ["worker.cc"], + hdrs = ["worker.h"], + deps = [ + "//include/envoy/server:worker_interface", + ] +) + +envoy_cc_mock( + name = "overload_manager_mocks", + srcs = ["overload_manager.cc"], + hdrs = ["overload_manager.h"], + deps = [ + "//include/envoy/server:overload_manager_interface", + ] +) + +envoy_cc_mock( + name = "instance_mocks", + srcs = ["instance.cc"], + hdrs = ["instance.h"], + deps = [ + "//include/envoy/server:instance_interface", + "//source/common/grpc:context_lib", + "//source/common/http:context_lib", + "//source/common/secret:secret_manager_impl_lib", + "//source/common/singleton:manager_impl_lib", + "//source/common/stats:stats_lib", + "//source/extensions/transport_sockets/tls:context_lib", + "//test/mocks/access_log:access_log_mocks", + "//test/mocks/api:api_mocks", + "//test/mocks/http:http_mocks", + "//test/mocks/init:init_mocks", + "//test/mocks/local_info:local_info_mocks", + "//test/mocks/network:network_mocks", + "//test/mocks/protobuf:protobuf_mocks", + "//test/mocks/router:router_mocks", + "//test/mocks/runtime:runtime_mocks", + "//test/mocks/secret:secret_mocks", + "//test/mocks/thread_local:thread_local_mocks", + "//test/mocks/tracing:tracing_mocks", + "//test/mocks/upstream:upstream_mocks", + + "//test/mocks/server:admin_mocks", + "//test/mocks/server:listener_manager_mocks", + "//test/mocks/server:server_lifecycle_notifier_mocks", + "//test/mocks/server:drain_manager_mocks", + "//test/mocks/server:overload_manager_mocks", + "//test/mocks/server:transport_socket_factory_context_mocks", + "//test/mocks/server:options_mocks", + "//test/mocks/server:hot_restart_mocks", + ] +) + +envoy_cc_mock( + name = "main_mocks", + srcs = ["main.cc"], + hdrs = ["main.h"], + deps = [ + "//include/envoy/server:overload_manager_interface", + "//include/envoy/server:configuration_interface", + ] +) + +envoy_cc_mock( + name = "factory_context_mocks", + srcs = ["factory_context.cc"], + hdrs = ["factory_context.h"], + deps = [ + "//test/mocks/server:server_lifecycle_notifier_mocks", + "//test/mocks/server:drain_manager_mocks", + "//test/mocks/server:overload_manager_mocks", + "//test/mocks/server:instance_mocks", + ] +) + +envoy_cc_mock( + name = "transport_socket_factory_context_mocks", + srcs = ["transport_socket_factory_context.cc"], + hdrs = ["transport_socket_factory_context.h"], + deps = [ + "//include/envoy/server:tracer_config_interface", + "//test/mocks/server:config_tracker_mocks", + "//test/mocks/upstream:upstream_mocks", + "//test/mocks/api:api_mocks", + "//source/common/secret:secret_manager_impl_lib", + ] +) + +envoy_cc_mock( + name = "listener_factory_context_mocks", + srcs = ["listener_factory_context.cc"], + hdrs = ["listener_factory_context.h"], + deps = [ + "//include/envoy/server:listener_manager_interface", + "//test/mocks/server:factory_context_mocks", + ] +) + +envoy_cc_mock( + name = "health_checker_factory_context_mocks", + srcs = ["health_checker_factory_context.cc"], + hdrs = ["health_checker_factory_context.h"], + deps = [ + "//include/envoy/server:health_checker_config_interface", + "//test/mocks/api:api_mocks", + "//test/mocks/event:event_mocks", + "//test/mocks/protobuf:protobuf_mocks", + "//test/mocks/router:router_mocks", + "//test/mocks/runtime:runtime_mocks", + "//test/mocks/upstream:upstream_mocks", + ] +) + +envoy_cc_mock( + name = "filter_chain_factory_context_mocks", + srcs = ["filter_chain_factory_context.cc"], + hdrs = ["filter_chain_factory_context.h"], + deps = [ + "//include/envoy/server:filter_config_interface", + "//test/mocks/server:factory_context_mocks", + ] +) + +envoy_cc_mock( + name = "tracer_factory_mocks", + srcs = ["tracer_factory.cc"], + hdrs = ["tracer_factory.h"], + deps = [ + "//include/envoy/server:tracer_config_interface", + "//include/envoy/protobuf:message_validator_interface", + ] +) + +envoy_cc_mock( + name = "tracer_factory_context_mocks", + srcs = ["tracer_factory_context.cc"], + hdrs = ["tracer_factory_context.h"], + deps = [ + + ] +) + + + envoy_cc_mock( name = "server_mocks", srcs = ["mocks.cc"], diff --git a/test/mocks/server/admin_stream.cc b/test/mocks/server/admin_stream.cc new file mode 100644 index 000000000000..1c039069c847 --- /dev/null +++ b/test/mocks/server/admin_stream.cc @@ -0,0 +1,25 @@ +#include "admin_stream.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockAdminStream::MockAdminStream() = default; + +MockAdminStream::~MockAdminStream() = default; + + + +} + +} diff --git a/test/mocks/server/admin_stream.h b/test/mocks/server/admin_stream.h new file mode 100644 index 000000000000..5410037fb781 --- /dev/null +++ b/test/mocks/server/admin_stream.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/admin.h" +#include "test/mocks/http/mocks.h" + +#include "absl/strings/string_view.h" +#include "gmock/gmock.h" +#include "spdlog/spdlog.h" + +namespace Envoy { +namespace Server { +class MockAdminStream : public AdminStream { +public: + MockAdminStream(); + ~MockAdminStream() override; + + MOCK_METHOD(void, setEndStreamOnComplete, (bool)); + MOCK_METHOD(void, addOnDestroyCallback, (std::function)); + MOCK_METHOD(const Buffer::Instance*, getRequestBody, (), (const)); + MOCK_METHOD(Http::RequestHeaderMap&, getRequestHeaders, (), (const)); + MOCK_METHOD(NiceMock&, getDecoderFilterCallbacks, (), + (const)); + MOCK_METHOD(Http::Http1StreamEncoderOptionsOptRef, http1StreamEncoderOptions, ()); +}; +} + +} diff --git a/test/mocks/server/bootstrap_extension_factory.cc b/test/mocks/server/bootstrap_extension_factory.cc new file mode 100644 index 000000000000..489dcffb6077 --- /dev/null +++ b/test/mocks/server/bootstrap_extension_factory.cc @@ -0,0 +1,16 @@ +#include "bootstrap_extension_factory.h" + + +namespace Envoy { +namespace Server { +namespace Configuration { +MockBootstrapExtensionFactory::MockBootstrapExtensionFactory() = default; + +MockBootstrapExtensionFactory::~MockBootstrapExtensionFactory() = default; + + +} + +} + +} diff --git a/test/mocks/server/bootstrap_extension_factory.h b/test/mocks/server/bootstrap_extension_factory.h new file mode 100644 index 000000000000..564bc5b2665f --- /dev/null +++ b/test/mocks/server/bootstrap_extension_factory.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/bootstrap_extension_config.h" + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +namespace Configuration { +class MockBootstrapExtensionFactory : public BootstrapExtensionFactory { +public: + MockBootstrapExtensionFactory(); + ~MockBootstrapExtensionFactory() override; + + MOCK_METHOD(BootstrapExtensionPtr, createBootstrapExtension, + (const Protobuf::Message&, Configuration::ServerFactoryContext&), (override)); + MOCK_METHOD(ProtobufTypes::MessagePtr, createEmptyConfigProto, (), (override)); + MOCK_METHOD(std::string, name, (), (const, override)); +}; +} + +} + +} diff --git a/test/mocks/server/drain_manager.cc b/test/mocks/server/drain_manager.cc new file mode 100644 index 000000000000..75f8ce8a74d8 --- /dev/null +++ b/test/mocks/server/drain_manager.cc @@ -0,0 +1,27 @@ +#include "drain_manager.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockDrainManager::MockDrainManager() { + ON_CALL(*this, startDrainSequence(_)).WillByDefault(SaveArg<0>(&drain_sequence_completion_)); +} + +MockDrainManager::~MockDrainManager() = default; + + + +} + +} diff --git a/test/mocks/server/drain_manager.h b/test/mocks/server/drain_manager.h new file mode 100644 index 000000000000..01134be7eae3 --- /dev/null +++ b/test/mocks/server/drain_manager.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/drain_manager.h" +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +class MockDrainManager : public DrainManager { +public: + MockDrainManager(); + ~MockDrainManager() override; + + // Server::DrainManager + MOCK_METHOD(bool, drainClose, (), (const)); + MOCK_METHOD(bool, draining, (), (const)); + MOCK_METHOD(void, startDrainSequence, (std::function completion)); + MOCK_METHOD(void, startParentShutdownSequence, ()); + + std::function drain_sequence_completion_; +}; +} + +} diff --git a/test/mocks/server/factory_context.cc b/test/mocks/server/factory_context.cc new file mode 100644 index 000000000000..5484057c3db0 --- /dev/null +++ b/test/mocks/server/factory_context.cc @@ -0,0 +1,56 @@ +#include "factory_context.h" + +#include + +#include "common/singleton/manager_impl.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +namespace Configuration { +MockFactoryContext::MockFactoryContext() + : singleton_manager_(new Singleton::ManagerImpl(Thread::threadFactoryForTest())), + grpc_context_(scope_.symbolTable()), http_context_(scope_.symbolTable()) { + ON_CALL(*this, getServerFactoryContext()).WillByDefault(ReturnRef(server_factory_context_)); + ON_CALL(*this, accessLogManager()).WillByDefault(ReturnRef(access_log_manager_)); + ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); + ON_CALL(*this, dispatcher()).WillByDefault(ReturnRef(dispatcher_)); + ON_CALL(*this, drainDecision()).WillByDefault(ReturnRef(drain_manager_)); + ON_CALL(*this, initManager()).WillByDefault(ReturnRef(init_manager_)); + ON_CALL(*this, lifecycleNotifier()).WillByDefault(ReturnRef(lifecycle_notifier_)); + ON_CALL(*this, localInfo()).WillByDefault(ReturnRef(local_info_)); + ON_CALL(*this, random()).WillByDefault(ReturnRef(random_)); + ON_CALL(*this, runtime()).WillByDefault(ReturnRef(runtime_loader_)); + ON_CALL(*this, scope()).WillByDefault(ReturnRef(scope_)); + ON_CALL(*this, singletonManager()).WillByDefault(ReturnRef(*singleton_manager_)); + ON_CALL(*this, threadLocal()).WillByDefault(ReturnRef(thread_local_)); + ON_CALL(*this, admin()).WillByDefault(ReturnRef(admin_)); + ON_CALL(*this, listenerScope()).WillByDefault(ReturnRef(listener_scope_)); + ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); + ON_CALL(*this, timeSource()).WillByDefault(ReturnRef(time_system_)); + ON_CALL(*this, overloadManager()).WillByDefault(ReturnRef(overload_manager_)); + ON_CALL(*this, messageValidationContext()).WillByDefault(ReturnRef(validation_context_)); + ON_CALL(*this, messageValidationVisitor()) + .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); + ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); +} + + +MockFactoryContext::~MockFactoryContext() = default; + + + +} + +} + +} diff --git a/test/mocks/server/factory_context.h b/test/mocks/server/factory_context.h new file mode 100644 index 000000000000..a9cf35e526d9 --- /dev/null +++ b/test/mocks/server/factory_context.h @@ -0,0 +1,83 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/configuration.h" + +#include "extensions/transport_sockets/tls/context_manager_impl.h" + +#include "absl/strings/string_view.h" +#include "admin.h" +#include "config_tracker.h" +#include "gmock/gmock.h" +#include "spdlog/spdlog.h" + +#include "server_lifecycle_notifier.h" +#include "drain_manager.h" +#include "overload_manager.h" +#include "instance.h" +namespace Envoy { +namespace Server { +namespace Configuration { +class MockFactoryContext : public virtual FactoryContext { +public: + MockFactoryContext(); + ~MockFactoryContext() override; + + MOCK_METHOD(ServerFactoryContext&, getServerFactoryContext, (), (const)); + MOCK_METHOD(TransportSocketFactoryContext&, getTransportSocketFactoryContext, (), (const)); + MOCK_METHOD(AccessLog::AccessLogManager&, accessLogManager, ()); + MOCK_METHOD(Upstream::ClusterManager&, clusterManager, ()); + MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); + MOCK_METHOD(const Network::DrainDecision&, drainDecision, ()); + MOCK_METHOD(bool, healthCheckFailed, ()); + MOCK_METHOD(Init::Manager&, initManager, ()); + MOCK_METHOD(ServerLifecycleNotifier&, lifecycleNotifier, ()); + MOCK_METHOD(Envoy::Runtime::RandomGenerator&, random, ()); + MOCK_METHOD(Envoy::Runtime::Loader&, runtime, ()); + MOCK_METHOD(Stats::Scope&, scope, ()); + MOCK_METHOD(Singleton::Manager&, singletonManager, ()); + MOCK_METHOD(OverloadManager&, overloadManager, ()); + MOCK_METHOD(ThreadLocal::Instance&, threadLocal, ()); + MOCK_METHOD(Server::Admin&, admin, ()); + MOCK_METHOD(Stats::Scope&, listenerScope, ()); + MOCK_METHOD(const LocalInfo::LocalInfo&, localInfo, (), (const)); + MOCK_METHOD(const envoy::config::core::v3::Metadata&, listenerMetadata, (), (const)); + MOCK_METHOD(envoy::config::core::v3::TrafficDirection, direction, (), (const)); + MOCK_METHOD(TimeSource&, timeSource, ()); + Event::TestTimeSystem& timeSystem() { return time_system_; } + Grpc::Context& grpcContext() override { return grpc_context_; } + Http::Context& httpContext() override { return http_context_; } + MOCK_METHOD(ProcessContextOptRef, processContext, ()); + MOCK_METHOD(ProtobufMessage::ValidationContext&, messageValidationContext, ()); + MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); + MOCK_METHOD(Api::Api&, api, ()); + + testing::NiceMock server_factory_context_; + testing::NiceMock access_log_manager_; + testing::NiceMock cluster_manager_; + testing::NiceMock dispatcher_; + testing::NiceMock drain_manager_; + testing::NiceMock init_manager_; + testing::NiceMock lifecycle_notifier_; + testing::NiceMock local_info_; + testing::NiceMock random_; + testing::NiceMock runtime_loader_; + testing::NiceMock scope_; + testing::NiceMock thread_local_; + Singleton::ManagerPtr singleton_manager_; + testing::NiceMock admin_; + Stats::IsolatedStoreImpl listener_scope_; + Event::GlobalTimeSystem time_system_; + testing::NiceMock validation_context_; + testing::NiceMock overload_manager_; + Grpc::ContextImpl grpc_context_; + Http::ContextImpl http_context_; + testing::NiceMock api_; +}; +} +} +} diff --git a/test/mocks/server/filter_chain_factory_context.cc b/test/mocks/server/filter_chain_factory_context.cc new file mode 100644 index 000000000000..2acd52988471 --- /dev/null +++ b/test/mocks/server/filter_chain_factory_context.cc @@ -0,0 +1,28 @@ +#include "filter_chain_factory_context.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +namespace Configuration { +MockFilterChainFactoryContext::MockFilterChainFactoryContext() = default; + +MockFilterChainFactoryContext::~MockFilterChainFactoryContext() = default; + + + +} + +} + +} diff --git a/test/mocks/server/filter_chain_factory_context.h b/test/mocks/server/filter_chain_factory_context.h new file mode 100644 index 000000000000..48c623dd6242 --- /dev/null +++ b/test/mocks/server/filter_chain_factory_context.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/filter_config.h" + +#include "factory_context.h" +namespace Envoy { +namespace Server { +namespace Configuration { +class MockFilterChainFactoryContext : public MockFactoryContext, public FilterChainFactoryContext { +public: + MockFilterChainFactoryContext(); + ~MockFilterChainFactoryContext() override; +}; +} + +} + +} diff --git a/test/mocks/server/guard_dog.cc b/test/mocks/server/guard_dog.cc new file mode 100644 index 000000000000..fc1eb69a756d --- /dev/null +++ b/test/mocks/server/guard_dog.cc @@ -0,0 +1,28 @@ +#include "guard_dog.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; +using testing::NiceMock; + +namespace Envoy { +namespace Server { +MockGuardDog::MockGuardDog() : watch_dog_(new NiceMock()) { + ON_CALL(*this, createWatchDog(_, _)).WillByDefault(Return(watch_dog_)); +} + +MockGuardDog::~MockGuardDog() = default; + + + +} + +} diff --git a/test/mocks/server/guard_dog.h b/test/mocks/server/guard_dog.h new file mode 100644 index 000000000000..920f1fd298e1 --- /dev/null +++ b/test/mocks/server/guard_dog.h @@ -0,0 +1,25 @@ +#pragma once + +#include "envoy/server/guarddog.h" + +#include "watch_dog.h" + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +class MockGuardDog : public GuardDog { +public: + MockGuardDog(); + ~MockGuardDog() override; + + // Server::GuardDog + MOCK_METHOD(WatchDogSharedPtr, createWatchDog, + (Thread::ThreadId thread_id, const std::string& thread_name)); + MOCK_METHOD(void, stopWatching, (WatchDogSharedPtr wd)); + + std::shared_ptr watch_dog_; +}; +} + +} diff --git a/test/mocks/server/health_checker_factory_context.cc b/test/mocks/server/health_checker_factory_context.cc new file mode 100644 index 000000000000..8db55f9b8098 --- /dev/null +++ b/test/mocks/server/health_checker_factory_context.cc @@ -0,0 +1,40 @@ +#include "health_checker_factory_context.h" + +#include + + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +namespace Configuration { +MockHealthCheckerFactoryContext::MockHealthCheckerFactoryContext() { + event_logger_ = new testing::NiceMock(); + ON_CALL(*this, cluster()).WillByDefault(ReturnRef(cluster_)); + ON_CALL(*this, dispatcher()).WillByDefault(ReturnRef(dispatcher_)); + ON_CALL(*this, random()).WillByDefault(ReturnRef(random_)); + ON_CALL(*this, runtime()).WillByDefault(ReturnRef(runtime_)); + ON_CALL(*this, eventLogger_()).WillByDefault(Return(event_logger_)); + ON_CALL(*this, messageValidationVisitor()) + .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); + ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); +} + + +MockHealthCheckerFactoryContext::~MockHealthCheckerFactoryContext() = default; + + + +} + +} + +} diff --git a/test/mocks/server/health_checker_factory_context.h b/test/mocks/server/health_checker_factory_context.h new file mode 100644 index 000000000000..1e7b602ba83c --- /dev/null +++ b/test/mocks/server/health_checker_factory_context.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/health_checker_config.h" + + +#include "test/mocks/api/mocks.h" +#include "test/mocks/event/mocks.h" +#include "test/mocks/protobuf/mocks.h" +#include "test/mocks/router/mocks.h" +#include "test/mocks/runtime/mocks.h" +#include "test/mocks/upstream/mocks.h" + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +namespace Configuration { +class MockHealthCheckerFactoryContext : public virtual HealthCheckerFactoryContext { +public: + MockHealthCheckerFactoryContext(); + ~MockHealthCheckerFactoryContext() override; + + MOCK_METHOD(Upstream::Cluster&, cluster, ()); + MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); + MOCK_METHOD(Envoy::Runtime::RandomGenerator&, random, ()); + MOCK_METHOD(Envoy::Runtime::Loader&, runtime, ()); + MOCK_METHOD(Upstream::HealthCheckEventLogger*, eventLogger_, ()); + MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); + MOCK_METHOD(Api::Api&, api, ()); + Upstream::HealthCheckEventLoggerPtr eventLogger() override { + return Upstream::HealthCheckEventLoggerPtr(eventLogger_()); + } + + testing::NiceMock cluster_; + testing::NiceMock dispatcher_; + testing::NiceMock random_; + testing::NiceMock runtime_; + testing::NiceMock* event_logger_{}; + testing::NiceMock api_{}; +}; +} + +} + +} diff --git a/test/mocks/server/hot_restart.cc b/test/mocks/server/hot_restart.cc new file mode 100644 index 000000000000..3d1992848658 --- /dev/null +++ b/test/mocks/server/hot_restart.cc @@ -0,0 +1,29 @@ +#include "hot_restart.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockHotRestart::MockHotRestart() : stats_allocator_(*symbol_table_) { + ON_CALL(*this, logLock()).WillByDefault(ReturnRef(log_lock_)); + ON_CALL(*this, accessLogLock()).WillByDefault(ReturnRef(access_log_lock_)); + ON_CALL(*this, statsAllocator()).WillByDefault(ReturnRef(stats_allocator_)); +} + +MockHotRestart::~MockHotRestart() = default; + + + +} + +} diff --git a/test/mocks/server/hot_restart.h b/test/mocks/server/hot_restart.h new file mode 100644 index 000000000000..e2b31214e0e9 --- /dev/null +++ b/test/mocks/server/hot_restart.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/instance.h" + +#include "test/mocks/stats/mocks.h" + + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +class MockHotRestart : public HotRestart { +public: + MockHotRestart(); + ~MockHotRestart() override; + + // Server::HotRestart + MOCK_METHOD(void, drainParentListeners, ()); + MOCK_METHOD(int, duplicateParentListenSocket, (const std::string& address)); + MOCK_METHOD(std::unique_ptr, getParentStats, ()); + MOCK_METHOD(void, initialize, (Event::Dispatcher & dispatcher, Server::Instance& server)); + MOCK_METHOD(void, sendParentAdminShutdownRequest, (time_t & original_start_time)); + MOCK_METHOD(void, sendParentTerminateRequest, ()); + MOCK_METHOD(ServerStatsFromParent, mergeParentStatsIfAny, (Stats::StoreRoot & stats_store)); + MOCK_METHOD(void, shutdown, ()); + MOCK_METHOD(uint32_t, baseId, ()); + MOCK_METHOD(std::string, version, ()); + MOCK_METHOD(Thread::BasicLockable&, logLock, ()); + MOCK_METHOD(Thread::BasicLockable&, accessLogLock, ()); + MOCK_METHOD(Stats::Allocator&, statsAllocator, ()); + +private: + Stats::TestSymbolTable symbol_table_; + Thread::MutexBasicLockable log_lock_; + Thread::MutexBasicLockable access_log_lock_; + Stats::AllocatorImpl stats_allocator_; +}; +} + +} diff --git a/test/mocks/server/instance.cc b/test/mocks/server/instance.cc new file mode 100644 index 000000000000..4992c3ccf9a6 --- /dev/null +++ b/test/mocks/server/instance.cc @@ -0,0 +1,79 @@ +#include "instance.h" + +#include + +#include "common/singleton/manager_impl.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockInstance::MockInstance() + : secret_manager_(std::make_unique(admin_.getConfigTracker())), + cluster_manager_(timeSource()), ssl_context_manager_(timeSource()), + singleton_manager_(new Singleton::ManagerImpl(Thread::threadFactoryForTest())), + grpc_context_(stats_store_.symbolTable()), http_context_(stats_store_.symbolTable()), + server_factory_context_( + std::make_shared>()), + transport_socket_factory_context_( + std::make_shared>()) { + ON_CALL(*this, threadLocal()).WillByDefault(ReturnRef(thread_local_)); + ON_CALL(*this, stats()).WillByDefault(ReturnRef(stats_store_)); + ON_CALL(*this, grpcContext()).WillByDefault(ReturnRef(grpc_context_)); + ON_CALL(*this, httpContext()).WillByDefault(ReturnRef(http_context_)); + ON_CALL(*this, dnsResolver()).WillByDefault(Return(dns_resolver_)); + ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); + ON_CALL(*this, admin()).WillByDefault(ReturnRef(admin_)); + ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); + ON_CALL(*this, sslContextManager()).WillByDefault(ReturnRef(ssl_context_manager_)); + ON_CALL(*this, accessLogManager()).WillByDefault(ReturnRef(access_log_manager_)); + ON_CALL(*this, runtime()).WillByDefault(ReturnRef(runtime_loader_)); + ON_CALL(*this, dispatcher()).WillByDefault(ReturnRef(dispatcher_)); + ON_CALL(*this, hotRestart()).WillByDefault(ReturnRef(hot_restart_)); + ON_CALL(*this, random()).WillByDefault(ReturnRef(random_)); + ON_CALL(*this, lifecycleNotifier()).WillByDefault(ReturnRef(lifecycle_notifier_)); + ON_CALL(*this, localInfo()).WillByDefault(ReturnRef(local_info_)); + ON_CALL(*this, options()).WillByDefault(ReturnRef(options_)); + ON_CALL(*this, drainManager()).WillByDefault(ReturnRef(drain_manager_)); + ON_CALL(*this, initManager()).WillByDefault(ReturnRef(init_manager_)); + ON_CALL(*this, listenerManager()).WillByDefault(ReturnRef(listener_manager_)); + ON_CALL(*this, mutexTracer()).WillByDefault(Return(nullptr)); + ON_CALL(*this, singletonManager()).WillByDefault(ReturnRef(*singleton_manager_)); + ON_CALL(*this, overloadManager()).WillByDefault(ReturnRef(overload_manager_)); + ON_CALL(*this, messageValidationContext()).WillByDefault(ReturnRef(validation_context_)); + ON_CALL(*this, serverFactoryContext()).WillByDefault(ReturnRef(*server_factory_context_)); + ON_CALL(*this, transportSocketFactoryContext()) + .WillByDefault(ReturnRef(*transport_socket_factory_context_)); +} + + +MockInstance::~MockInstance() = default; + +namespace Configuration { + +MockTransportSocketFactoryContext::MockTransportSocketFactoryContext() + : secret_manager_(std::make_unique(config_tracker_)) { + ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); + ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); + ON_CALL(*this, messageValidationVisitor()) + .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); +} + + +MockTransportSocketFactoryContext::~MockTransportSocketFactoryContext() = default; + + +} + + +} + +} diff --git a/test/mocks/server/instance.h b/test/mocks/server/instance.h new file mode 100644 index 000000000000..4b4bd76fbc7c --- /dev/null +++ b/test/mocks/server/instance.h @@ -0,0 +1,177 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/instance.h" + +#include "common/grpc/context_impl.h" +#include "common/http/context_impl.h" +#include "common/stats/fake_symbol_table_impl.h" +#include "extensions/transport_sockets/tls/context_manager_impl.h" + +#include "test/mocks/access_log/mocks.h" +#include "test/mocks/api/mocks.h" +#include "test/mocks/event/mocks.h" +#include "test/mocks/http/mocks.h" +#include "test/mocks/init/mocks.h" +#include "test/mocks/local_info/mocks.h" +#include "test/mocks/network/mocks.h" +#include "test/mocks/protobuf/mocks.h" +#include "test/mocks/runtime/mocks.h" +#include "test/mocks/secret/mocks.h" +#include "test/mocks/stats/mocks.h" +#include "test/mocks/thread_local/mocks.h" +#include "test/mocks/tracing/mocks.h" +#include "test/mocks/upstream/mocks.h" + +#include "gmock/gmock.h" + +#include "listener_manager.h" +#include "server_lifecycle_notifier.h" +#include "drain_manager.h" +#include "overload_manager.h" +#include "admin.h" +#include "transport_socket_factory_context.h" +#include "options.h" +#include "hot_restart.h" +namespace Envoy { +namespace Server { +namespace Configuration { +class MockServerFactoryContext; +} // namespace Configuration + +class MockInstance : public Instance { +public: + MockInstance(); + ~MockInstance() override; + + Secret::SecretManager& secretManager() override { return *(secret_manager_.get()); } + + MOCK_METHOD(Admin&, admin, ()); + MOCK_METHOD(Api::Api&, api, ()); + MOCK_METHOD(Upstream::ClusterManager&, clusterManager, ()); + MOCK_METHOD(Ssl::ContextManager&, sslContextManager, ()); + MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); + MOCK_METHOD(Network::DnsResolverSharedPtr, dnsResolver, ()); + MOCK_METHOD(void, drainListeners, ()); + MOCK_METHOD(DrainManager&, drainManager, ()); + MOCK_METHOD(AccessLog::AccessLogManager&, accessLogManager, ()); + MOCK_METHOD(void, failHealthcheck, (bool fail)); + MOCK_METHOD(void, exportStatsToChild, (envoy::HotRestartMessage::Reply::Stats*)); + MOCK_METHOD(bool, healthCheckFailed, ()); + MOCK_METHOD(HotRestart&, hotRestart, ()); + MOCK_METHOD(Init::Manager&, initManager, ()); + MOCK_METHOD(ServerLifecycleNotifier&, lifecycleNotifier, ()); + MOCK_METHOD(ListenerManager&, listenerManager, ()); + MOCK_METHOD(Envoy::MutexTracer*, mutexTracer, ()); + MOCK_METHOD(const Options&, options, ()); + MOCK_METHOD(OverloadManager&, overloadManager, ()); + MOCK_METHOD(Runtime::RandomGenerator&, random, ()); + MOCK_METHOD(Runtime::Loader&, runtime, ()); + MOCK_METHOD(void, shutdown, ()); + MOCK_METHOD(bool, isShutdown, ()); + MOCK_METHOD(void, shutdownAdmin, ()); + MOCK_METHOD(Singleton::Manager&, singletonManager, ()); + MOCK_METHOD(time_t, startTimeCurrentEpoch, ()); + MOCK_METHOD(time_t, startTimeFirstEpoch, ()); + MOCK_METHOD(Stats::Store&, stats, ()); + MOCK_METHOD(Grpc::Context&, grpcContext, ()); + MOCK_METHOD(Http::Context&, httpContext, ()); + MOCK_METHOD(ProcessContextOptRef, processContext, ()); + MOCK_METHOD(ThreadLocal::Instance&, threadLocal, ()); + MOCK_METHOD(const LocalInfo::LocalInfo&, localInfo, (), (const)); + MOCK_METHOD(std::chrono::milliseconds, statsFlushInterval, (), (const)); + MOCK_METHOD(void, flushStats, ()); + MOCK_METHOD(ProtobufMessage::ValidationContext&, messageValidationContext, ()); + MOCK_METHOD(Configuration::ServerFactoryContext&, serverFactoryContext, ()); + MOCK_METHOD(Configuration::TransportSocketFactoryContext&, transportSocketFactoryContext, ()); + + void setDefaultTracingConfig(const envoy::config::trace::v3::Tracing& tracing_config) override { + http_context_.setDefaultTracingConfig(tracing_config); + } + + TimeSource& timeSource() override { return time_system_; } + + NiceMock stats_store_; + testing::NiceMock thread_local_; + std::shared_ptr> dns_resolver_{ + new testing::NiceMock()}; + testing::NiceMock api_; + testing::NiceMock admin_; + Event::GlobalTimeSystem time_system_; + std::unique_ptr secret_manager_; + testing::NiceMock cluster_manager_; + Thread::MutexBasicLockable access_log_lock_; + testing::NiceMock runtime_loader_; + Extensions::TransportSockets::Tls::ContextManagerImpl ssl_context_manager_; + testing::NiceMock dispatcher_; + testing::NiceMock drain_manager_; + testing::NiceMock access_log_manager_; + testing::NiceMock hot_restart_; + testing::NiceMock options_; + testing::NiceMock random_; + testing::NiceMock lifecycle_notifier_; + testing::NiceMock local_info_; + testing::NiceMock init_manager_; + testing::NiceMock listener_manager_; + testing::NiceMock overload_manager_; + Singleton::ManagerPtr singleton_manager_; + Grpc::ContextImpl grpc_context_; + Http::ContextImpl http_context_; + testing::NiceMock validation_context_; + std::shared_ptr> + server_factory_context_; + std::shared_ptr> + transport_socket_factory_context_; +}; + + +namespace Configuration { +class MockServerFactoryContext : public virtual ServerFactoryContext { +public: + MockServerFactoryContext(); + ~MockServerFactoryContext() override; + + MOCK_METHOD(Upstream::ClusterManager&, clusterManager, ()); + MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); + MOCK_METHOD(const Network::DrainDecision&, drainDecision, ()); + MOCK_METHOD(const LocalInfo::LocalInfo&, localInfo, (), (const)); + MOCK_METHOD(Envoy::Runtime::RandomGenerator&, random, ()); + MOCK_METHOD(Envoy::Runtime::Loader&, runtime, ()); + MOCK_METHOD(Stats::Scope&, scope, ()); + MOCK_METHOD(Singleton::Manager&, singletonManager, ()); + MOCK_METHOD(ThreadLocal::Instance&, threadLocal, ()); + MOCK_METHOD(Server::Admin&, admin, ()); + MOCK_METHOD(TimeSource&, timeSource, ()); + Event::TestTimeSystem& timeSystem() { return time_system_; } + MOCK_METHOD(ProtobufMessage::ValidationContext&, messageValidationContext, ()); + MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); + MOCK_METHOD(Api::Api&, api, ()); + Grpc::Context& grpcContext() override { return grpc_context_; } + MOCK_METHOD(Server::DrainManager&, drainManager, ()); + MOCK_METHOD(Init::Manager&, initManager, ()); + MOCK_METHOD(ServerLifecycleNotifier&, lifecycleNotifier, ()); + + testing::NiceMock cluster_manager_; + testing::NiceMock dispatcher_; + testing::NiceMock drain_manager_; + testing::NiceMock local_info_; + testing::NiceMock random_; + testing::NiceMock runtime_loader_; + testing::NiceMock scope_; + testing::NiceMock thread_local_; + testing::NiceMock validation_context_; + Singleton::ManagerPtr singleton_manager_; + testing::NiceMock admin_; + Event::GlobalTimeSystem time_system_; + testing::NiceMock api_; + Grpc::ContextImpl grpc_context_; +}; +} + +} + +} diff --git a/test/mocks/server/listener_component_factory.cc b/test/mocks/server/listener_component_factory.cc new file mode 100644 index 000000000000..c46faf064516 --- /dev/null +++ b/test/mocks/server/listener_component_factory.cc @@ -0,0 +1,40 @@ +#include "listener_component_factory.h" + +#include + +#include "envoy/admin/v3/server_info.pb.h" +#include "envoy/config/core/v3/base.pb.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockListenerComponentFactory::MockListenerComponentFactory() + : socket_(std::make_shared>()) { + ON_CALL(*this, createListenSocket(_, _, _, _)) + .WillByDefault(Invoke([&](Network::Address::InstanceConstSharedPtr, Network::Socket::Type, + const Network::Socket::OptionsSharedPtr& options, + const ListenSocketCreationParams&) -> Network::SocketSharedPtr { + if (!Network::Socket::applyOptions(options, *socket_, + envoy::config::core::v3::SocketOption::STATE_PREBIND)) { + throw EnvoyException("MockListenerComponentFactory: Setting socket options failed"); + } + return socket_; + })); +} + +MockListenerComponentFactory::~MockListenerComponentFactory() = default; + + + +} + +} diff --git a/test/mocks/server/listener_component_factory.h b/test/mocks/server/listener_component_factory.h new file mode 100644 index 000000000000..0a0c9942ce7d --- /dev/null +++ b/test/mocks/server/listener_component_factory.h @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/listener_manager.h" +#include "envoy/server/drain_manager.h" +#include "envoy/config/listener/v3/listener_components.pb.h" + +#include "test/mocks/network/mocks.h" + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +class MockListenerComponentFactory : public ListenerComponentFactory { +public: + MockListenerComponentFactory(); + ~MockListenerComponentFactory() override; + + DrainManagerPtr + createDrainManager(envoy::config::listener::v3::Listener::DrainType drain_type) override { + return DrainManagerPtr{createDrainManager_(drain_type)}; + } + LdsApiPtr createLdsApi(const envoy::config::core::v3::ConfigSource& lds_config) override { + return LdsApiPtr{createLdsApi_(lds_config)}; + } + + MOCK_METHOD(LdsApi*, createLdsApi_, (const envoy::config::core::v3::ConfigSource& lds_config)); + MOCK_METHOD(std::vector, createNetworkFilterFactoryList, + (const Protobuf::RepeatedPtrField& filters, + Configuration::FilterChainFactoryContext& filter_chain_factory_context)); + MOCK_METHOD(std::vector, createListenerFilterFactoryList, + (const Protobuf::RepeatedPtrField&, + Configuration::ListenerFactoryContext& context)); + MOCK_METHOD(std::vector, createUdpListenerFilterFactoryList, + (const Protobuf::RepeatedPtrField&, + Configuration::ListenerFactoryContext& context)); + MOCK_METHOD(Network::SocketSharedPtr, createListenSocket, + (Network::Address::InstanceConstSharedPtr address, Network::Socket::Type socket_type, + const Network::Socket::OptionsSharedPtr& options, + const ListenSocketCreationParams& params)); + MOCK_METHOD(DrainManager*, createDrainManager_, + (envoy::config::listener::v3::Listener::DrainType drain_type)); + MOCK_METHOD(uint64_t, nextListenerTag, ()); + + std::shared_ptr socket_; +}; +} + +} diff --git a/test/mocks/server/listener_factory_context.cc b/test/mocks/server/listener_factory_context.cc new file mode 100644 index 000000000000..604b0856eafb --- /dev/null +++ b/test/mocks/server/listener_factory_context.cc @@ -0,0 +1,26 @@ +#include "listener_factory_context.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +namespace Configuration { +MockListenerFactoryContext::MockListenerFactoryContext() = default; + +MockListenerFactoryContext::~MockListenerFactoryContext() = default; + + + +} + +} + +} diff --git a/test/mocks/server/listener_factory_context.h b/test/mocks/server/listener_factory_context.h new file mode 100644 index 000000000000..391db5f178fc --- /dev/null +++ b/test/mocks/server/listener_factory_context.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/listener_manager.h" + +#include "gmock/gmock.h" + +#include "factory_context.h" +namespace Envoy { +namespace Server { +namespace Configuration { +class MockListenerFactoryContext : public MockFactoryContext, public ListenerFactoryContext { +public: + MockListenerFactoryContext(); + ~MockListenerFactoryContext() override; + + const Network::ListenerConfig& listenerConfig() const override { return listener_config_; } + MOCK_METHOD(const Network::ListenerConfig&, listenerConfig_, (), (const)); + + Network::MockListenerConfig listener_config_; +}; +} + +} + +} diff --git a/test/mocks/server/listener_manager.cc b/test/mocks/server/listener_manager.cc new file mode 100644 index 000000000000..9fadb32925aa --- /dev/null +++ b/test/mocks/server/listener_manager.cc @@ -0,0 +1,25 @@ +#include "listener_manager.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockListenerManager::MockListenerManager() = default; + +MockListenerManager::~MockListenerManager() = default; + + + +} + +} diff --git a/test/mocks/server/listener_manager.h b/test/mocks/server/listener_manager.h new file mode 100644 index 000000000000..dafc76315ae1 --- /dev/null +++ b/test/mocks/server/listener_manager.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/listener_manager.h" + + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +class MockListenerManager : public ListenerManager { +public: + MockListenerManager(); + ~MockListenerManager() override; + + MOCK_METHOD(bool, addOrUpdateListener, + (const envoy::config::listener::v3::Listener& config, const std::string& version_info, + bool modifiable)); + MOCK_METHOD(void, createLdsApi, (const envoy::config::core::v3::ConfigSource& lds_config)); + MOCK_METHOD(std::vector>, listeners, ()); + MOCK_METHOD(uint64_t, numConnections, (), (const)); + MOCK_METHOD(bool, removeListener, (const std::string& listener_name)); + MOCK_METHOD(void, startWorkers, (GuardDog & guard_dog)); + MOCK_METHOD(void, stopListeners, (StopListenersType listeners_type)); + MOCK_METHOD(void, stopWorkers, ()); + MOCK_METHOD(void, beginListenerUpdate, ()); + MOCK_METHOD(void, endListenerUpdate, (ListenerManager::FailureStates &&)); + MOCK_METHOD(ApiListenerOptRef, apiListener, ()); +}; +} + +} diff --git a/test/mocks/server/main.cc b/test/mocks/server/main.cc new file mode 100644 index 000000000000..47f924b5f17a --- /dev/null +++ b/test/mocks/server/main.cc @@ -0,0 +1,35 @@ +#include "main.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +namespace Configuration { +MockMain::MockMain(int wd_miss, int wd_megamiss, int wd_kill, int wd_multikill) + : wd_miss_(wd_miss), wd_megamiss_(wd_megamiss), wd_kill_(wd_kill), wd_multikill_(wd_multikill) { + ON_CALL(*this, wdMissTimeout()).WillByDefault(Return(wd_miss_)); + ON_CALL(*this, wdMegaMissTimeout()).WillByDefault(Return(wd_megamiss_)); + ON_CALL(*this, wdKillTimeout()).WillByDefault(Return(wd_kill_)); + ON_CALL(*this, wdMultiKillTimeout()).WillByDefault(Return(wd_multikill_)); +} + + +MockMain::~MockMain() = default; + + + +} + +} + +} diff --git a/test/mocks/server/main.h b/test/mocks/server/main.h new file mode 100644 index 000000000000..313bdcf1528b --- /dev/null +++ b/test/mocks/server/main.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/overload_manager.h" +#include "envoy/server/configuration.h" + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +namespace Configuration { +class MockMain : public Main { +public: + MockMain() : MockMain(0, 0, 0, 0) {} + MockMain(int wd_miss, int wd_megamiss, int wd_kill, int wd_multikill); + ~MockMain() override; + + MOCK_METHOD(Upstream::ClusterManager*, clusterManager, ()); + MOCK_METHOD(std::list&, statsSinks, ()); + MOCK_METHOD(std::chrono::milliseconds, statsFlushInterval, (), (const)); + MOCK_METHOD(std::chrono::milliseconds, wdMissTimeout, (), (const)); + MOCK_METHOD(std::chrono::milliseconds, wdMegaMissTimeout, (), (const)); + MOCK_METHOD(std::chrono::milliseconds, wdKillTimeout, (), (const)); + MOCK_METHOD(std::chrono::milliseconds, wdMultiKillTimeout, (), (const)); + + std::chrono::milliseconds wd_miss_; + std::chrono::milliseconds wd_megamiss_; + std::chrono::milliseconds wd_kill_; + std::chrono::milliseconds wd_multikill_; +}; +} + +} + +} diff --git a/test/mocks/server/options.cc b/test/mocks/server/options.cc new file mode 100644 index 000000000000..04e85013e33c --- /dev/null +++ b/test/mocks/server/options.cc @@ -0,0 +1,57 @@ +#include "options.h" + +#include + +#include "envoy/admin/v3/server_info.pb.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockOptions::MockOptions(const std::string& config_path) : config_path_(config_path) { + ON_CALL(*this, concurrency()).WillByDefault(ReturnPointee(&concurrency_)); + ON_CALL(*this, configPath()).WillByDefault(ReturnRef(config_path_)); + ON_CALL(*this, configProto()).WillByDefault(ReturnRef(config_proto_)); + ON_CALL(*this, configYaml()).WillByDefault(ReturnRef(config_yaml_)); + ON_CALL(*this, bootstrapVersion()).WillByDefault(ReturnRef(bootstrap_version_)); + ON_CALL(*this, allowUnknownStaticFields()).WillByDefault(Invoke([this] { + return allow_unknown_static_fields_; + })); + ON_CALL(*this, rejectUnknownDynamicFields()).WillByDefault(Invoke([this] { + return reject_unknown_dynamic_fields_; + })); + ON_CALL(*this, ignoreUnknownDynamicFields()).WillByDefault(Invoke([this] { + return ignore_unknown_dynamic_fields_; + })); + ON_CALL(*this, adminAddressPath()).WillByDefault(ReturnRef(admin_address_path_)); + ON_CALL(*this, serviceClusterName()).WillByDefault(ReturnRef(service_cluster_name_)); + ON_CALL(*this, serviceNodeName()).WillByDefault(ReturnRef(service_node_name_)); + ON_CALL(*this, serviceZone()).WillByDefault(ReturnRef(service_zone_name_)); + ON_CALL(*this, logLevel()).WillByDefault(Return(log_level_)); + ON_CALL(*this, logPath()).WillByDefault(ReturnRef(log_path_)); + ON_CALL(*this, restartEpoch()).WillByDefault(ReturnPointee(&hot_restart_epoch_)); + ON_CALL(*this, hotRestartDisabled()).WillByDefault(ReturnPointee(&hot_restart_disabled_)); + ON_CALL(*this, signalHandlingEnabled()).WillByDefault(ReturnPointee(&signal_handling_enabled_)); + ON_CALL(*this, mutexTracingEnabled()).WillByDefault(ReturnPointee(&mutex_tracing_enabled_)); + ON_CALL(*this, cpusetThreadsEnabled()).WillByDefault(ReturnPointee(&cpuset_threads_enabled_)); + ON_CALL(*this, disabledExtensions()).WillByDefault(ReturnRef(disabled_extensions_)); + ON_CALL(*this, toCommandLineOptions()).WillByDefault(Invoke([] { + return std::make_unique(); + })); +} + +MockOptions::~MockOptions() = default; + + + +} + +} diff --git a/test/mocks/server/options.h b/test/mocks/server/options.h new file mode 100644 index 000000000000..50befaa3b412 --- /dev/null +++ b/test/mocks/server/options.h @@ -0,0 +1,82 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/config/bootstrap/v3/bootstrap.pb.h" +#include "envoy/server/options.h" + +#include "absl/strings/string_view.h" +#include "gmock/gmock.h" +#include "spdlog/spdlog.h" + +namespace Envoy { +namespace Server { +class MockOptions : public Options { +public: + MockOptions() : MockOptions(std::string()) {} + MockOptions(const std::string& config_path); + ~MockOptions() override; + + MOCK_METHOD(uint64_t, baseId, (), (const)); + MOCK_METHOD(bool, useDynamicBaseId, (), (const)); + MOCK_METHOD(const std::string&, baseIdPath, (), (const)); + MOCK_METHOD(uint32_t, concurrency, (), (const)); + MOCK_METHOD(const std::string&, configPath, (), (const)); + MOCK_METHOD(const envoy::config::bootstrap::v3::Bootstrap&, configProto, (), (const)); + MOCK_METHOD(const std::string&, configYaml, (), (const)); + MOCK_METHOD(const absl::optional&, bootstrapVersion, (), (const)); + MOCK_METHOD(bool, allowUnknownStaticFields, (), (const)); + MOCK_METHOD(bool, rejectUnknownDynamicFields, (), (const)); + MOCK_METHOD(bool, ignoreUnknownDynamicFields, (), (const)); + MOCK_METHOD(const std::string&, adminAddressPath, (), (const)); + MOCK_METHOD(Network::Address::IpVersion, localAddressIpVersion, (), (const)); + MOCK_METHOD(std::chrono::seconds, drainTime, (), (const)); + MOCK_METHOD(std::chrono::seconds, parentShutdownTime, (), (const)); + MOCK_METHOD(Server::DrainStrategy, drainStrategy, (), (const)); + MOCK_METHOD(spdlog::level::level_enum, logLevel, (), (const)); + MOCK_METHOD((const std::vector>&), + componentLogLevels, (), (const)); + MOCK_METHOD(const std::string&, logFormat, (), (const)); + MOCK_METHOD(bool, logFormatEscaped, (), (const)); + MOCK_METHOD(const std::string&, logPath, (), (const)); + MOCK_METHOD(uint64_t, restartEpoch, (), (const)); + MOCK_METHOD(std::chrono::milliseconds, fileFlushIntervalMsec, (), (const)); + MOCK_METHOD(Mode, mode, (), (const)); + MOCK_METHOD(const std::string&, serviceClusterName, (), (const)); + MOCK_METHOD(const std::string&, serviceNodeName, (), (const)); + MOCK_METHOD(const std::string&, serviceZone, (), (const)); + MOCK_METHOD(bool, hotRestartDisabled, (), (const)); + MOCK_METHOD(bool, signalHandlingEnabled, (), (const)); + MOCK_METHOD(bool, mutexTracingEnabled, (), (const)); + MOCK_METHOD(bool, fakeSymbolTableEnabled, (), (const)); + MOCK_METHOD(bool, cpusetThreadsEnabled, (), (const)); + MOCK_METHOD(const std::vector&, disabledExtensions, (), (const)); + MOCK_METHOD(Server::CommandLineOptionsPtr, toCommandLineOptions, (), (const)); + + std::string config_path_; + envoy::config::bootstrap::v3::Bootstrap config_proto_; + std::string config_yaml_; + absl::optional bootstrap_version_; + bool allow_unknown_static_fields_{}; + bool reject_unknown_dynamic_fields_{}; + bool ignore_unknown_dynamic_fields_{}; + std::string admin_address_path_; + std::string service_cluster_name_; + std::string service_node_name_; + std::string service_zone_name_; + spdlog::level::level_enum log_level_{spdlog::level::trace}; + std::string log_path_; + uint32_t concurrency_{1}; + uint64_t hot_restart_epoch_{}; + bool hot_restart_disabled_{}; + bool signal_handling_enabled_{true}; + bool mutex_tracing_enabled_{}; + bool cpuset_threads_enabled_{}; + std::vector disabled_extensions_; +}; +} + +} diff --git a/test/mocks/server/overload_manager.cc b/test/mocks/server/overload_manager.cc new file mode 100644 index 000000000000..dbe04d629183 --- /dev/null +++ b/test/mocks/server/overload_manager.cc @@ -0,0 +1,28 @@ +#include "overload_manager.h" + +#include + + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockOverloadManager::MockOverloadManager() { + ON_CALL(*this, getThreadLocalOverloadState()).WillByDefault(ReturnRef(overload_state_)); +} + +MockOverloadManager::~MockOverloadManager() = default; + + + +} + +} diff --git a/test/mocks/server/overload_manager.h b/test/mocks/server/overload_manager.h new file mode 100644 index 000000000000..baf9c55c3ec1 --- /dev/null +++ b/test/mocks/server/overload_manager.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/overload_manager.h" + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +class MockOverloadManager : public OverloadManager { +public: + MockOverloadManager(); + ~MockOverloadManager() override; + + // OverloadManager + MOCK_METHOD(void, start, ()); + MOCK_METHOD(bool, registerForAction, + (const std::string& action, Event::Dispatcher& dispatcher, + OverloadActionCb callback)); + MOCK_METHOD(ThreadLocalOverloadState&, getThreadLocalOverloadState, ()); + + ThreadLocalOverloadState overload_state_; +}; +} + +} diff --git a/test/mocks/server/server_lifecycle_notifier.cc b/test/mocks/server/server_lifecycle_notifier.cc new file mode 100644 index 000000000000..056e6b471dfd --- /dev/null +++ b/test/mocks/server/server_lifecycle_notifier.cc @@ -0,0 +1,25 @@ +#include "server_lifecycle_notifier.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockServerLifecycleNotifier::MockServerLifecycleNotifier() = default; + +MockServerLifecycleNotifier::~MockServerLifecycleNotifier() = default; + + + +} + +} diff --git a/test/mocks/server/server_lifecycle_notifier.h b/test/mocks/server/server_lifecycle_notifier.h new file mode 100644 index 000000000000..182f63985081 --- /dev/null +++ b/test/mocks/server/server_lifecycle_notifier.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/lifecycle_notifier.h" + +#include "gmock/gmock.h" +#include "spdlog/spdlog.h" + +namespace Envoy { +namespace Server { +class MockServerLifecycleNotifier : public ServerLifecycleNotifier { +public: + MockServerLifecycleNotifier(); + ~MockServerLifecycleNotifier() override; + + MOCK_METHOD(ServerLifecycleNotifier::HandlePtr, registerCallback, (Stage, StageCallback)); + MOCK_METHOD(ServerLifecycleNotifier::HandlePtr, registerCallback, + (Stage, StageCallbackWithCompletion)); +}; +} + +} diff --git a/test/mocks/server/tracer_factory.cc b/test/mocks/server/tracer_factory.cc new file mode 100644 index 000000000000..4a34d9ab2e3e --- /dev/null +++ b/test/mocks/server/tracer_factory.cc @@ -0,0 +1,32 @@ +#include "tracer_factory.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +namespace Configuration { +MockTracerFactory::MockTracerFactory(const std::string& name) : name_(name) { + ON_CALL(*this, createEmptyConfigProto()).WillByDefault(Invoke([] { + return std::make_unique(); + })); +} + +MockTracerFactory::~MockTracerFactory() = default; + + + +} + +} + +} diff --git a/test/mocks/server/tracer_factory.h b/test/mocks/server/tracer_factory.h new file mode 100644 index 000000000000..2814545d2b4e --- /dev/null +++ b/test/mocks/server/tracer_factory.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/tracer_config.h" +#include "envoy/protobuf/message_validator.h" + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +namespace Configuration { +class MockTracerFactory : public TracerFactory { +public: + explicit MockTracerFactory(const std::string& name); + ~MockTracerFactory() override; + + std::string name() const override { return name_; } + + MOCK_METHOD(ProtobufTypes::MessagePtr, createEmptyConfigProto, ()); + MOCK_METHOD(Tracing::HttpTracerSharedPtr, createHttpTracer, + (const Protobuf::Message& config, TracerFactoryContext& context)); + +private: + std::string name_; +}; +} + +} + +} diff --git a/test/mocks/server/tracer_factory_context.cc b/test/mocks/server/tracer_factory_context.cc new file mode 100644 index 000000000000..a136c85b03e8 --- /dev/null +++ b/test/mocks/server/tracer_factory_context.cc @@ -0,0 +1,33 @@ +#include "tracer_factory_context.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +namespace Configuration { +MockTracerFactoryContext::MockTracerFactoryContext() { + ON_CALL(*this, serverFactoryContext()).WillByDefault(ReturnRef(server_factory_context_)); + ON_CALL(*this, messageValidationVisitor()) + .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); +} + + +MockTracerFactoryContext::~MockTracerFactoryContext() = default; + + + +} + +} + +} diff --git a/test/mocks/server/tracer_factory_context.h b/test/mocks/server/tracer_factory_context.h new file mode 100644 index 000000000000..8a561c5b4131 --- /dev/null +++ b/test/mocks/server/tracer_factory_context.h @@ -0,0 +1,80 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/common/mutex_tracer.h" +#include "envoy/config/bootstrap/v3/bootstrap.pb.h" +#include "envoy/config/core/v3/base.pb.h" +#include "envoy/config/core/v3/config_source.pb.h" +#include "envoy/config/listener/v3/listener.pb.h" +#include "envoy/config/listener/v3/listener_components.pb.h" +#include "envoy/protobuf/message_validator.h" +#include "envoy/server/admin.h" +#include "envoy/server/bootstrap_extension_config.h" +#include "envoy/server/configuration.h" +#include "envoy/server/drain_manager.h" +#include "envoy/server/filter_config.h" +#include "envoy/server/health_checker_config.h" +#include "envoy/server/instance.h" +#include "envoy/server/options.h" +#include "envoy/server/overload_manager.h" +#include "envoy/server/tracer_config.h" +#include "envoy/server/transport_socket_config.h" +#include "envoy/server/worker.h" +#include "envoy/ssl/context_manager.h" +#include "envoy/stats/scope.h" +#include "envoy/thread/thread.h" + +#include "common/grpc/context_impl.h" +#include "common/http/context_impl.h" +#include "common/secret/secret_manager_impl.h" +#include "common/stats/fake_symbol_table_impl.h" + +#include "extensions/transport_sockets/tls/context_manager_impl.h" + +#include "test/mocks/access_log/mocks.h" +#include "test/mocks/api/mocks.h" +#include "test/mocks/event/mocks.h" +#include "test/mocks/http/mocks.h" +#include "test/mocks/init/mocks.h" +#include "test/mocks/local_info/mocks.h" +#include "test/mocks/network/mocks.h" +#include "test/mocks/protobuf/mocks.h" +#include "test/mocks/router/mocks.h" +#include "test/mocks/runtime/mocks.h" +#include "test/mocks/secret/mocks.h" +#include "test/mocks/stats/mocks.h" +#include "test/mocks/thread_local/mocks.h" +#include "test/mocks/tracing/mocks.h" +#include "test/mocks/upstream/mocks.h" +#include "test/test_common/test_time_system.h" + +#include "absl/strings/string_view.h" +#include "admin.h" +#include "config_tracker.h" +#include "gmock/gmock.h" +#include "spdlog/spdlog.h" + +#include "instance.h" +#include "tracer_factory.h" +namespace Envoy { +namespace Server { +namespace Configuration { +class MockTracerFactoryContext : public TracerFactoryContext { +public: + MockTracerFactoryContext(); + ~MockTracerFactoryContext() override; + + MOCK_METHOD(ServerFactoryContext&, serverFactoryContext, ()); + MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); + + testing::NiceMock server_factory_context_; +}; +} + +} + +} diff --git a/test/mocks/server/transport_socket_factory_context.cc b/test/mocks/server/transport_socket_factory_context.cc new file mode 100644 index 000000000000..6118c4c7ab5a --- /dev/null +++ b/test/mocks/server/transport_socket_factory_context.cc @@ -0,0 +1,36 @@ +#include "transport_socket_factory_context.h" + +#include + + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +namespace Configuration { +MockTransportSocketFactoryContext::MockTransportSocketFactoryContext() + : secret_manager_(std::make_unique(config_tracker_)) { + ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); + ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); + ON_CALL(*this, messageValidationVisitor()) + .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); +} + + +MockTransportSocketFactoryContext::~MockTransportSocketFactoryContext() = default; + + + +} + +} + +} diff --git a/test/mocks/server/transport_socket_factory_context.h b/test/mocks/server/transport_socket_factory_context.h new file mode 100644 index 000000000000..e7b6e458fcc3 --- /dev/null +++ b/test/mocks/server/transport_socket_factory_context.h @@ -0,0 +1,51 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/transport_socket_config.h" + +#include "test/mocks/upstream/mocks.h" +#include "test/mocks/api/mocks.h" + +#include "common/secret/secret_manager_impl.h" + +#include "config_tracker.h" +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +namespace Configuration { +class MockTransportSocketFactoryContext : public TransportSocketFactoryContext { +public: + MockTransportSocketFactoryContext(); + ~MockTransportSocketFactoryContext() override; + + Secret::SecretManager& secretManager() override { return *(secret_manager_.get()); } + + MOCK_METHOD(Server::Admin&, admin, ()); + MOCK_METHOD(Ssl::ContextManager&, sslContextManager, ()); + MOCK_METHOD(Stats::Scope&, scope, ()); + MOCK_METHOD(Upstream::ClusterManager&, clusterManager, ()); + MOCK_METHOD(const LocalInfo::LocalInfo&, localInfo, (), (const)); + MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); + MOCK_METHOD(Envoy::Runtime::RandomGenerator&, random, ()); + MOCK_METHOD(Stats::Store&, stats, ()); + MOCK_METHOD(Init::Manager&, initManager, ()); + MOCK_METHOD(Singleton::Manager&, singletonManager, ()); + MOCK_METHOD(ThreadLocal::SlotAllocator&, threadLocal, ()); + MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); + MOCK_METHOD(Api::Api&, api, ()); + + testing::NiceMock cluster_manager_; + testing::NiceMock api_; + testing::NiceMock config_tracker_; + std::unique_ptr secret_manager_; +}; +} + +} + +} diff --git a/test/mocks/server/watch_dog.cc b/test/mocks/server/watch_dog.cc new file mode 100644 index 000000000000..d6b8a7133294 --- /dev/null +++ b/test/mocks/server/watch_dog.cc @@ -0,0 +1,25 @@ +#include "watch_dog.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockWatchDog::MockWatchDog() = default; + +MockWatchDog::~MockWatchDog() = default; + + + +} + +} diff --git a/test/mocks/server/watch_dog.h b/test/mocks/server/watch_dog.h new file mode 100644 index 000000000000..902b2ab6c377 --- /dev/null +++ b/test/mocks/server/watch_dog.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/watchdog.h" + +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +class MockWatchDog : public WatchDog { +public: + MockWatchDog(); + ~MockWatchDog() override; + + // Server::WatchDog + MOCK_METHOD(void, startWatchdog, (Event::Dispatcher & dispatcher)); + MOCK_METHOD(void, touch, ()); + MOCK_METHOD(Thread::ThreadId, threadId, (), (const)); + MOCK_METHOD(MonotonicTime, lastTouchTime, (), (const)); +}; +} + +} diff --git a/test/mocks/server/worker.cc b/test/mocks/server/worker.cc new file mode 100644 index 000000000000..433898cbc3f1 --- /dev/null +++ b/test/mocks/server/worker.cc @@ -0,0 +1,56 @@ +#include "worker.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockWorker::MockWorker() { + ON_CALL(*this, addListener(_, _, _)) + .WillByDefault( + Invoke([this](absl::optional overridden_listener, + Network::ListenerConfig& config, AddListenerCompletion completion) -> void { + UNREFERENCED_PARAMETER(overridden_listener); + config.listenSocketFactory().getListenSocket(); + EXPECT_EQ(nullptr, add_listener_completion_); + add_listener_completion_ = completion; + })); + + ON_CALL(*this, removeListener(_, _)) + .WillByDefault( + Invoke([this](Network::ListenerConfig&, std::function completion) -> void { + EXPECT_EQ(nullptr, remove_listener_completion_); + remove_listener_completion_ = completion; + })); + + ON_CALL(*this, stopListener(_, _)) + .WillByDefault(Invoke([](Network::ListenerConfig&, std::function completion) -> void { + if (completion != nullptr) { + completion(); + } + })); + + ON_CALL(*this, removeFilterChains(_, _, _)) + .WillByDefault(Invoke([this](uint64_t, const std::list&, + std::function completion) -> void { + EXPECT_EQ(nullptr, remove_filter_chains_completion_); + remove_filter_chains_completion_ = completion; + })); +} + +MockWorker::~MockWorker() = default; + + + +} + +} diff --git a/test/mocks/server/worker.h b/test/mocks/server/worker.h new file mode 100644 index 000000000000..2ef4ad6096a0 --- /dev/null +++ b/test/mocks/server/worker.h @@ -0,0 +1,60 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/worker.h" + +#include "absl/strings/string_view.h" +#include "gmock/gmock.h" + +namespace Envoy { +namespace Server { +class MockWorker : public Worker { +public: + MockWorker(); + ~MockWorker() override; + + void callAddCompletion(bool success) { + EXPECT_NE(nullptr, add_listener_completion_); + add_listener_completion_(success); + add_listener_completion_ = nullptr; + } + + void callRemovalCompletion() { + EXPECT_NE(nullptr, remove_listener_completion_); + remove_listener_completion_(); + remove_listener_completion_ = nullptr; + } + + void callDrainFilterChainsComplete() { + EXPECT_NE(nullptr, remove_filter_chains_completion_); + remove_filter_chains_completion_(); + remove_filter_chains_completion_ = nullptr; + } + + // Server::Worker + MOCK_METHOD(void, addListener, + (absl::optional overridden_listener, Network::ListenerConfig& listener, + AddListenerCompletion completion)); + MOCK_METHOD(uint64_t, numConnections, (), (const)); + MOCK_METHOD(void, removeListener, + (Network::ListenerConfig & listener, std::function completion)); + MOCK_METHOD(void, start, (GuardDog & guard_dog)); + MOCK_METHOD(void, initializeStats, (Stats::Scope & scope)); + MOCK_METHOD(void, stop, ()); + MOCK_METHOD(void, stopListener, + (Network::ListenerConfig & listener, std::function completion)); + MOCK_METHOD(void, removeFilterChains, + (uint64_t listener_tag, const std::list& filter_chains, + std::function completion)); + + AddListenerCompletion add_listener_completion_; + std::function remove_listener_completion_; + std::function remove_filter_chains_completion_; +}; +} + +} diff --git a/test/mocks/server/worker_factory.cc b/test/mocks/server/worker_factory.cc new file mode 100644 index 000000000000..0f2017c7f12b --- /dev/null +++ b/test/mocks/server/worker_factory.cc @@ -0,0 +1,25 @@ +#include "worker_factory.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using testing::_; +using testing::Invoke; +using testing::Return; +using testing::ReturnPointee; +using testing::ReturnRef; +using testing::SaveArg; + +namespace Envoy { +namespace Server { +MockWorkerFactory::MockWorkerFactory() = default; + +MockWorkerFactory::~MockWorkerFactory() = default; + + + +} + +} diff --git a/test/mocks/server/worker_factory.h b/test/mocks/server/worker_factory.h new file mode 100644 index 000000000000..e31f0fd47deb --- /dev/null +++ b/test/mocks/server/worker_factory.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include +#include + +#include "envoy/server/worker.h" + +#include "gmock/gmock.h" + +#include "worker.h" +namespace Envoy { +namespace Server { +class MockWorkerFactory : public WorkerFactory { +public: + MockWorkerFactory(); + ~MockWorkerFactory() override; + + // Server::WorkerFactory + WorkerPtr createWorker(OverloadManager&, const std::string&) override { + return WorkerPtr{createWorker_()}; + } + + MOCK_METHOD(Worker*, createWorker_, ()); +}; +} + +} From e3c12fa07fe38d6470f411a242f264b2f929ad2d Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 29 Jun 2020 05:24:25 +0000 Subject: [PATCH 02/17] fix dependency issues Signed-off-by: Muge Chen --- test/mocks/server/BUILD | 65 +- test/mocks/server/mocks.cc | 293 --------- test/mocks/server/mocks.h | 680 +-------------------- test/mocks/server/tracer_factory_context.h | 48 -- 4 files changed, 47 insertions(+), 1039 deletions(-) diff --git a/test/mocks/server/BUILD b/test/mocks/server/BUILD index 116a189bc1aa..0b96d7a6f816 100644 --- a/test/mocks/server/BUILD +++ b/test/mocks/server/BUILD @@ -277,7 +277,9 @@ envoy_cc_mock( srcs = ["tracer_factory_context.cc"], hdrs = ["tracer_factory_context.h"], deps = [ - + "//include/envoy/server:configuration_interface", + "//test/mocks/server:instance_mocks", + "//test/mocks/server:tracer_factory_mocks", ] ) @@ -288,46 +290,29 @@ envoy_cc_mock( srcs = ["mocks.cc"], hdrs = ["mocks.h"], deps = [ - "//include/envoy/secret:secret_manager_interface", - "//include/envoy/server:admin_interface", - "//include/envoy/server:bootstrap_extension_config_interface", - "//include/envoy/server:configuration_interface", - "//include/envoy/server:drain_manager_interface", - "//include/envoy/server:filter_config_interface", - "//include/envoy/server:guarddog_interface", - "//include/envoy/server:health_checker_config_interface", - "//include/envoy/server:instance_interface", - "//include/envoy/server:options_interface", - "//include/envoy/server:overload_manager_interface", - "//include/envoy/server:tracer_config_interface", - "//include/envoy/server:worker_interface", - "//include/envoy/ssl:context_manager_interface", - "//include/envoy/upstream:health_checker_interface", - "//source/common/grpc:context_lib", - "//source/common/http:context_lib", - "//source/common/secret:secret_manager_impl_lib", - "//source/common/singleton:manager_impl_lib", - "//source/common/stats:stats_lib", - "//source/extensions/transport_sockets/tls:context_lib", - "//test/mocks/access_log:access_log_mocks", - "//test/mocks/api:api_mocks", - "//test/mocks/http:http_mocks", - "//test/mocks/init:init_mocks", - "//test/mocks/local_info:local_info_mocks", - "//test/mocks/network:network_mocks", - "//test/mocks/protobuf:protobuf_mocks", - "//test/mocks/router:router_mocks", - "//test/mocks/runtime:runtime_mocks", - "//test/mocks/secret:secret_mocks", "//test/mocks/server:admin_mocks", "//test/mocks/server:config_tracker_mocks", - "//test/mocks/thread_local:thread_local_mocks", - "//test/mocks/tracing:tracing_mocks", - "//test/mocks/upstream:upstream_mocks", - "//test/test_common:test_time_lib", - "@envoy_api//envoy/admin/v3:pkg_cc_proto", - "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto", - "@envoy_api//envoy/config/core/v3:pkg_cc_proto", - "@envoy_api//envoy/config/listener/v3:pkg_cc_proto", + "//test/mocks/server:drain_manager_mocks", + "//test/mocks/server:health_checker_factory_context_mocks", + "//test/mocks/server:listener_factory_context_mocks", + "//test/mocks/server:options_mocks", + "//test/mocks/server:tracer_factory_mocks", + "//test/mocks/server:worker_mocks", + "//test/mocks/server:admin_stream_mocks", + "//test/mocks/server:factory_context_mocks", + "//test/mocks/server:hot_restart_mocks", + "//test/mocks/server:listener_manager_mocks", + "//test/mocks/server:overload_manager_mocks", + "//test/mocks/server:transport_socket_factory_context_mocks", + "//test/mocks/server:bootstrap_extension_factory_mocks", + "//test/mocks/server:filter_chain_factory_context_mocks", + "//test/mocks/server:instance_mocks", + "//test/mocks/server:main_mocks", + "//test/mocks/server:server_lifecycle_notifier_mocks", + "//test/mocks/server:watch_dog_mocks", + "//test/mocks/server:guard_dog_mocks", + "//test/mocks/server:listener_component_factory_mocks", + "//test/mocks/server:tracer_factory_context_mocks", + "//test/mocks/server:worker_factory_mocks", ], ) diff --git a/test/mocks/server/mocks.cc b/test/mocks/server/mocks.cc index e9fc293558c5..87fb1d7c6ddb 100644 --- a/test/mocks/server/mocks.cc +++ b/test/mocks/server/mocks.cc @@ -1,295 +1,2 @@ #include "mocks.h" -#include - -#include "envoy/admin/v3/server_info.pb.h" -#include "envoy/config/core/v3/base.pb.h" - -#include "common/singleton/manager_impl.h" - -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; - -namespace Envoy { -namespace Server { - -MockOptions::MockOptions(const std::string& config_path) : config_path_(config_path) { - ON_CALL(*this, concurrency()).WillByDefault(ReturnPointee(&concurrency_)); - ON_CALL(*this, configPath()).WillByDefault(ReturnRef(config_path_)); - ON_CALL(*this, configProto()).WillByDefault(ReturnRef(config_proto_)); - ON_CALL(*this, configYaml()).WillByDefault(ReturnRef(config_yaml_)); - ON_CALL(*this, bootstrapVersion()).WillByDefault(ReturnRef(bootstrap_version_)); - ON_CALL(*this, allowUnknownStaticFields()).WillByDefault(Invoke([this] { - return allow_unknown_static_fields_; - })); - ON_CALL(*this, rejectUnknownDynamicFields()).WillByDefault(Invoke([this] { - return reject_unknown_dynamic_fields_; - })); - ON_CALL(*this, ignoreUnknownDynamicFields()).WillByDefault(Invoke([this] { - return ignore_unknown_dynamic_fields_; - })); - ON_CALL(*this, adminAddressPath()).WillByDefault(ReturnRef(admin_address_path_)); - ON_CALL(*this, serviceClusterName()).WillByDefault(ReturnRef(service_cluster_name_)); - ON_CALL(*this, serviceNodeName()).WillByDefault(ReturnRef(service_node_name_)); - ON_CALL(*this, serviceZone()).WillByDefault(ReturnRef(service_zone_name_)); - ON_CALL(*this, logLevel()).WillByDefault(Return(log_level_)); - ON_CALL(*this, logPath()).WillByDefault(ReturnRef(log_path_)); - ON_CALL(*this, restartEpoch()).WillByDefault(ReturnPointee(&hot_restart_epoch_)); - ON_CALL(*this, hotRestartDisabled()).WillByDefault(ReturnPointee(&hot_restart_disabled_)); - ON_CALL(*this, signalHandlingEnabled()).WillByDefault(ReturnPointee(&signal_handling_enabled_)); - ON_CALL(*this, mutexTracingEnabled()).WillByDefault(ReturnPointee(&mutex_tracing_enabled_)); - ON_CALL(*this, cpusetThreadsEnabled()).WillByDefault(ReturnPointee(&cpuset_threads_enabled_)); - ON_CALL(*this, disabledExtensions()).WillByDefault(ReturnRef(disabled_extensions_)); - ON_CALL(*this, toCommandLineOptions()).WillByDefault(Invoke([] { - return std::make_unique(); - })); -} -MockOptions::~MockOptions() = default; - -MockAdminStream::MockAdminStream() = default; -MockAdminStream::~MockAdminStream() = default; - -MockDrainManager::MockDrainManager() { - ON_CALL(*this, startDrainSequence(_)).WillByDefault(SaveArg<0>(&drain_sequence_completion_)); -} -MockDrainManager::~MockDrainManager() = default; - -MockWatchDog::MockWatchDog() = default; -MockWatchDog::~MockWatchDog() = default; - -MockGuardDog::MockGuardDog() : watch_dog_(new NiceMock()) { - ON_CALL(*this, createWatchDog(_, _)).WillByDefault(Return(watch_dog_)); -} -MockGuardDog::~MockGuardDog() = default; - -MockHotRestart::MockHotRestart() : stats_allocator_(*symbol_table_) { - ON_CALL(*this, logLock()).WillByDefault(ReturnRef(log_lock_)); - ON_CALL(*this, accessLogLock()).WillByDefault(ReturnRef(access_log_lock_)); - ON_CALL(*this, statsAllocator()).WillByDefault(ReturnRef(stats_allocator_)); -} -MockHotRestart::~MockHotRestart() = default; - -MockOverloadManager::MockOverloadManager() { - ON_CALL(*this, getThreadLocalOverloadState()).WillByDefault(ReturnRef(overload_state_)); -} -MockOverloadManager::~MockOverloadManager() = default; - -MockListenerComponentFactory::MockListenerComponentFactory() - : socket_(std::make_shared>()) { - ON_CALL(*this, createListenSocket(_, _, _, _)) - .WillByDefault(Invoke([&](Network::Address::InstanceConstSharedPtr, Network::Socket::Type, - const Network::Socket::OptionsSharedPtr& options, - const ListenSocketCreationParams&) -> Network::SocketSharedPtr { - if (!Network::Socket::applyOptions(options, *socket_, - envoy::config::core::v3::SocketOption::STATE_PREBIND)) { - throw EnvoyException("MockListenerComponentFactory: Setting socket options failed"); - } - return socket_; - })); -} -MockListenerComponentFactory::~MockListenerComponentFactory() = default; - -MockServerLifecycleNotifier::MockServerLifecycleNotifier() = default; -MockServerLifecycleNotifier::~MockServerLifecycleNotifier() = default; - -MockListenerManager::MockListenerManager() = default; -MockListenerManager::~MockListenerManager() = default; - -MockWorkerFactory::MockWorkerFactory() = default; -MockWorkerFactory::~MockWorkerFactory() = default; - -MockWorker::MockWorker() { - ON_CALL(*this, addListener(_, _, _)) - .WillByDefault( - Invoke([this](absl::optional overridden_listener, - Network::ListenerConfig& config, AddListenerCompletion completion) -> void { - UNREFERENCED_PARAMETER(overridden_listener); - config.listenSocketFactory().getListenSocket(); - EXPECT_EQ(nullptr, add_listener_completion_); - add_listener_completion_ = completion; - })); - - ON_CALL(*this, removeListener(_, _)) - .WillByDefault( - Invoke([this](Network::ListenerConfig&, std::function completion) -> void { - EXPECT_EQ(nullptr, remove_listener_completion_); - remove_listener_completion_ = completion; - })); - - ON_CALL(*this, stopListener(_, _)) - .WillByDefault(Invoke([](Network::ListenerConfig&, std::function completion) -> void { - if (completion != nullptr) { - completion(); - } - })); - - ON_CALL(*this, removeFilterChains(_, _, _)) - .WillByDefault(Invoke([this](uint64_t, const std::list&, - std::function completion) -> void { - EXPECT_EQ(nullptr, remove_filter_chains_completion_); - remove_filter_chains_completion_ = completion; - })); -} -MockWorker::~MockWorker() = default; - -MockInstance::MockInstance() - : secret_manager_(std::make_unique(admin_.getConfigTracker())), - cluster_manager_(timeSource()), ssl_context_manager_(timeSource()), - singleton_manager_(new Singleton::ManagerImpl(Thread::threadFactoryForTest())), - grpc_context_(stats_store_.symbolTable()), http_context_(stats_store_.symbolTable()), - server_factory_context_( - std::make_shared>()), - transport_socket_factory_context_( - std::make_shared>()) { - ON_CALL(*this, threadLocal()).WillByDefault(ReturnRef(thread_local_)); - ON_CALL(*this, stats()).WillByDefault(ReturnRef(stats_store_)); - ON_CALL(*this, grpcContext()).WillByDefault(ReturnRef(grpc_context_)); - ON_CALL(*this, httpContext()).WillByDefault(ReturnRef(http_context_)); - ON_CALL(*this, dnsResolver()).WillByDefault(Return(dns_resolver_)); - ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); - ON_CALL(*this, admin()).WillByDefault(ReturnRef(admin_)); - ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); - ON_CALL(*this, sslContextManager()).WillByDefault(ReturnRef(ssl_context_manager_)); - ON_CALL(*this, accessLogManager()).WillByDefault(ReturnRef(access_log_manager_)); - ON_CALL(*this, runtime()).WillByDefault(ReturnRef(runtime_loader_)); - ON_CALL(*this, dispatcher()).WillByDefault(ReturnRef(dispatcher_)); - ON_CALL(*this, hotRestart()).WillByDefault(ReturnRef(hot_restart_)); - ON_CALL(*this, random()).WillByDefault(ReturnRef(random_)); - ON_CALL(*this, lifecycleNotifier()).WillByDefault(ReturnRef(lifecycle_notifier_)); - ON_CALL(*this, localInfo()).WillByDefault(ReturnRef(local_info_)); - ON_CALL(*this, options()).WillByDefault(ReturnRef(options_)); - ON_CALL(*this, drainManager()).WillByDefault(ReturnRef(drain_manager_)); - ON_CALL(*this, initManager()).WillByDefault(ReturnRef(init_manager_)); - ON_CALL(*this, listenerManager()).WillByDefault(ReturnRef(listener_manager_)); - ON_CALL(*this, mutexTracer()).WillByDefault(Return(nullptr)); - ON_CALL(*this, singletonManager()).WillByDefault(ReturnRef(*singleton_manager_)); - ON_CALL(*this, overloadManager()).WillByDefault(ReturnRef(overload_manager_)); - ON_CALL(*this, messageValidationContext()).WillByDefault(ReturnRef(validation_context_)); - ON_CALL(*this, serverFactoryContext()).WillByDefault(ReturnRef(*server_factory_context_)); - ON_CALL(*this, transportSocketFactoryContext()) - .WillByDefault(ReturnRef(*transport_socket_factory_context_)); -} - -MockInstance::~MockInstance() = default; - -namespace Configuration { - -MockMain::MockMain(int wd_miss, int wd_megamiss, int wd_kill, int wd_multikill) - : wd_miss_(wd_miss), wd_megamiss_(wd_megamiss), wd_kill_(wd_kill), wd_multikill_(wd_multikill) { - ON_CALL(*this, wdMissTimeout()).WillByDefault(Return(wd_miss_)); - ON_CALL(*this, wdMegaMissTimeout()).WillByDefault(Return(wd_megamiss_)); - ON_CALL(*this, wdKillTimeout()).WillByDefault(Return(wd_kill_)); - ON_CALL(*this, wdMultiKillTimeout()).WillByDefault(Return(wd_multikill_)); -} - -MockMain::~MockMain() = default; - -MockServerFactoryContext::MockServerFactoryContext() - : singleton_manager_(new Singleton::ManagerImpl(Thread::threadFactoryForTest())), - grpc_context_(scope_.symbolTable()) { - ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); - ON_CALL(*this, dispatcher()).WillByDefault(ReturnRef(dispatcher_)); - ON_CALL(*this, drainDecision()).WillByDefault(ReturnRef(drain_manager_)); - ON_CALL(*this, localInfo()).WillByDefault(ReturnRef(local_info_)); - ON_CALL(*this, random()).WillByDefault(ReturnRef(random_)); - ON_CALL(*this, runtime()).WillByDefault(ReturnRef(runtime_loader_)); - ON_CALL(*this, scope()).WillByDefault(ReturnRef(scope_)); - ON_CALL(*this, singletonManager()).WillByDefault(ReturnRef(*singleton_manager_)); - ON_CALL(*this, threadLocal()).WillByDefault(ReturnRef(thread_local_)); - ON_CALL(*this, admin()).WillByDefault(ReturnRef(admin_)); - ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); - ON_CALL(*this, timeSource()).WillByDefault(ReturnRef(time_system_)); - ON_CALL(*this, messageValidationContext()).WillByDefault(ReturnRef(validation_context_)); - ON_CALL(*this, messageValidationVisitor()) - .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); - ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); - ON_CALL(*this, drainManager()).WillByDefault(ReturnRef(drain_manager_)); -} -MockServerFactoryContext::~MockServerFactoryContext() = default; - -MockFactoryContext::MockFactoryContext() - : singleton_manager_(new Singleton::ManagerImpl(Thread::threadFactoryForTest())), - grpc_context_(scope_.symbolTable()), http_context_(scope_.symbolTable()) { - ON_CALL(*this, getServerFactoryContext()).WillByDefault(ReturnRef(server_factory_context_)); - ON_CALL(*this, accessLogManager()).WillByDefault(ReturnRef(access_log_manager_)); - ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); - ON_CALL(*this, dispatcher()).WillByDefault(ReturnRef(dispatcher_)); - ON_CALL(*this, drainDecision()).WillByDefault(ReturnRef(drain_manager_)); - ON_CALL(*this, initManager()).WillByDefault(ReturnRef(init_manager_)); - ON_CALL(*this, lifecycleNotifier()).WillByDefault(ReturnRef(lifecycle_notifier_)); - ON_CALL(*this, localInfo()).WillByDefault(ReturnRef(local_info_)); - ON_CALL(*this, random()).WillByDefault(ReturnRef(random_)); - ON_CALL(*this, runtime()).WillByDefault(ReturnRef(runtime_loader_)); - ON_CALL(*this, scope()).WillByDefault(ReturnRef(scope_)); - ON_CALL(*this, singletonManager()).WillByDefault(ReturnRef(*singleton_manager_)); - ON_CALL(*this, threadLocal()).WillByDefault(ReturnRef(thread_local_)); - ON_CALL(*this, admin()).WillByDefault(ReturnRef(admin_)); - ON_CALL(*this, listenerScope()).WillByDefault(ReturnRef(listener_scope_)); - ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); - ON_CALL(*this, timeSource()).WillByDefault(ReturnRef(time_system_)); - ON_CALL(*this, overloadManager()).WillByDefault(ReturnRef(overload_manager_)); - ON_CALL(*this, messageValidationContext()).WillByDefault(ReturnRef(validation_context_)); - ON_CALL(*this, messageValidationVisitor()) - .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); - ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); -} - -MockFactoryContext::~MockFactoryContext() = default; - -MockTransportSocketFactoryContext::MockTransportSocketFactoryContext() - : secret_manager_(std::make_unique(config_tracker_)) { - ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); - ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); - ON_CALL(*this, messageValidationVisitor()) - .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); -} - -MockTransportSocketFactoryContext::~MockTransportSocketFactoryContext() = default; - -MockListenerFactoryContext::MockListenerFactoryContext() = default; -MockListenerFactoryContext::~MockListenerFactoryContext() = default; - -MockHealthCheckerFactoryContext::MockHealthCheckerFactoryContext() { - event_logger_ = new NiceMock(); - ON_CALL(*this, cluster()).WillByDefault(ReturnRef(cluster_)); - ON_CALL(*this, dispatcher()).WillByDefault(ReturnRef(dispatcher_)); - ON_CALL(*this, random()).WillByDefault(ReturnRef(random_)); - ON_CALL(*this, runtime()).WillByDefault(ReturnRef(runtime_)); - ON_CALL(*this, eventLogger_()).WillByDefault(Return(event_logger_)); - ON_CALL(*this, messageValidationVisitor()) - .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); - ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); -} - -MockHealthCheckerFactoryContext::~MockHealthCheckerFactoryContext() = default; - -MockFilterChainFactoryContext::MockFilterChainFactoryContext() = default; -MockFilterChainFactoryContext::~MockFilterChainFactoryContext() = default; - -MockTracerFactory::MockTracerFactory(const std::string& name) : name_(name) { - ON_CALL(*this, createEmptyConfigProto()).WillByDefault(Invoke([] { - return std::make_unique(); - })); -} -MockTracerFactory::~MockTracerFactory() = default; - -MockTracerFactoryContext::MockTracerFactoryContext() { - ON_CALL(*this, serverFactoryContext()).WillByDefault(ReturnRef(server_factory_context_)); - ON_CALL(*this, messageValidationVisitor()) - .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); -} - -MockTracerFactoryContext::~MockTracerFactoryContext() = default; - -MockBootstrapExtensionFactory::MockBootstrapExtensionFactory() = default; -MockBootstrapExtensionFactory::~MockBootstrapExtensionFactory() = default; -} // namespace Configuration -} // namespace Server -} // namespace Envoy diff --git a/test/mocks/server/mocks.h b/test/mocks/server/mocks.h index 1685d0f706d2..60c6fdd7afc4 100644 --- a/test/mocks/server/mocks.h +++ b/test/mocks/server/mocks.h @@ -1,661 +1,25 @@ #pragma once - -#include -#include -#include -#include - -#include "envoy/common/mutex_tracer.h" -#include "envoy/config/bootstrap/v3/bootstrap.pb.h" -#include "envoy/config/core/v3/base.pb.h" -#include "envoy/config/core/v3/config_source.pb.h" -#include "envoy/config/listener/v3/listener.pb.h" -#include "envoy/config/listener/v3/listener_components.pb.h" -#include "envoy/protobuf/message_validator.h" -#include "envoy/server/admin.h" -#include "envoy/server/bootstrap_extension_config.h" -#include "envoy/server/configuration.h" -#include "envoy/server/drain_manager.h" -#include "envoy/server/filter_config.h" -#include "envoy/server/health_checker_config.h" -#include "envoy/server/instance.h" -#include "envoy/server/options.h" -#include "envoy/server/overload_manager.h" -#include "envoy/server/tracer_config.h" -#include "envoy/server/transport_socket_config.h" -#include "envoy/server/worker.h" -#include "envoy/ssl/context_manager.h" -#include "envoy/stats/scope.h" -#include "envoy/thread/thread.h" - -#include "common/grpc/context_impl.h" -#include "common/http/context_impl.h" -#include "common/secret/secret_manager_impl.h" -#include "common/stats/fake_symbol_table_impl.h" - -#include "extensions/transport_sockets/tls/context_manager_impl.h" - -#include "test/mocks/access_log/mocks.h" -#include "test/mocks/api/mocks.h" -#include "test/mocks/event/mocks.h" -#include "test/mocks/http/mocks.h" -#include "test/mocks/init/mocks.h" -#include "test/mocks/local_info/mocks.h" -#include "test/mocks/network/mocks.h" -#include "test/mocks/protobuf/mocks.h" -#include "test/mocks/router/mocks.h" -#include "test/mocks/runtime/mocks.h" -#include "test/mocks/secret/mocks.h" -#include "test/mocks/stats/mocks.h" -#include "test/mocks/thread_local/mocks.h" -#include "test/mocks/tracing/mocks.h" -#include "test/mocks/upstream/mocks.h" -#include "test/test_common/test_time_system.h" - -#include "absl/strings/string_view.h" #include "admin.h" #include "config_tracker.h" -#include "gmock/gmock.h" -#include "spdlog/spdlog.h" - -namespace Envoy { -namespace Server { - -namespace Configuration { -class MockServerFactoryContext; -class MockTransportSocketFactoryContext; -} // namespace Configuration - -class MockOptions : public Options { -public: - MockOptions() : MockOptions(std::string()) {} - MockOptions(const std::string& config_path); - ~MockOptions() override; - - MOCK_METHOD(uint64_t, baseId, (), (const)); - MOCK_METHOD(bool, useDynamicBaseId, (), (const)); - MOCK_METHOD(const std::string&, baseIdPath, (), (const)); - MOCK_METHOD(uint32_t, concurrency, (), (const)); - MOCK_METHOD(const std::string&, configPath, (), (const)); - MOCK_METHOD(const envoy::config::bootstrap::v3::Bootstrap&, configProto, (), (const)); - MOCK_METHOD(const std::string&, configYaml, (), (const)); - MOCK_METHOD(const absl::optional&, bootstrapVersion, (), (const)); - MOCK_METHOD(bool, allowUnknownStaticFields, (), (const)); - MOCK_METHOD(bool, rejectUnknownDynamicFields, (), (const)); - MOCK_METHOD(bool, ignoreUnknownDynamicFields, (), (const)); - MOCK_METHOD(const std::string&, adminAddressPath, (), (const)); - MOCK_METHOD(Network::Address::IpVersion, localAddressIpVersion, (), (const)); - MOCK_METHOD(std::chrono::seconds, drainTime, (), (const)); - MOCK_METHOD(std::chrono::seconds, parentShutdownTime, (), (const)); - MOCK_METHOD(Server::DrainStrategy, drainStrategy, (), (const)); - MOCK_METHOD(spdlog::level::level_enum, logLevel, (), (const)); - MOCK_METHOD((const std::vector>&), - componentLogLevels, (), (const)); - MOCK_METHOD(const std::string&, logFormat, (), (const)); - MOCK_METHOD(bool, logFormatEscaped, (), (const)); - MOCK_METHOD(const std::string&, logPath, (), (const)); - MOCK_METHOD(uint64_t, restartEpoch, (), (const)); - MOCK_METHOD(std::chrono::milliseconds, fileFlushIntervalMsec, (), (const)); - MOCK_METHOD(Mode, mode, (), (const)); - MOCK_METHOD(const std::string&, serviceClusterName, (), (const)); - MOCK_METHOD(const std::string&, serviceNodeName, (), (const)); - MOCK_METHOD(const std::string&, serviceZone, (), (const)); - MOCK_METHOD(bool, hotRestartDisabled, (), (const)); - MOCK_METHOD(bool, signalHandlingEnabled, (), (const)); - MOCK_METHOD(bool, mutexTracingEnabled, (), (const)); - MOCK_METHOD(bool, fakeSymbolTableEnabled, (), (const)); - MOCK_METHOD(bool, cpusetThreadsEnabled, (), (const)); - MOCK_METHOD(const std::vector&, disabledExtensions, (), (const)); - MOCK_METHOD(Server::CommandLineOptionsPtr, toCommandLineOptions, (), (const)); - - std::string config_path_; - envoy::config::bootstrap::v3::Bootstrap config_proto_; - std::string config_yaml_; - absl::optional bootstrap_version_; - bool allow_unknown_static_fields_{}; - bool reject_unknown_dynamic_fields_{}; - bool ignore_unknown_dynamic_fields_{}; - std::string admin_address_path_; - std::string service_cluster_name_; - std::string service_node_name_; - std::string service_zone_name_; - spdlog::level::level_enum log_level_{spdlog::level::trace}; - std::string log_path_; - uint32_t concurrency_{1}; - uint64_t hot_restart_epoch_{}; - bool hot_restart_disabled_{}; - bool signal_handling_enabled_{true}; - bool mutex_tracing_enabled_{}; - bool cpuset_threads_enabled_{}; - std::vector disabled_extensions_; -}; - -class MockAdminStream : public AdminStream { -public: - MockAdminStream(); - ~MockAdminStream() override; - - MOCK_METHOD(void, setEndStreamOnComplete, (bool)); - MOCK_METHOD(void, addOnDestroyCallback, (std::function)); - MOCK_METHOD(const Buffer::Instance*, getRequestBody, (), (const)); - MOCK_METHOD(Http::RequestHeaderMap&, getRequestHeaders, (), (const)); - MOCK_METHOD(NiceMock&, getDecoderFilterCallbacks, (), - (const)); - MOCK_METHOD(Http::Http1StreamEncoderOptionsOptRef, http1StreamEncoderOptions, ()); -}; - -class MockDrainManager : public DrainManager { -public: - MockDrainManager(); - ~MockDrainManager() override; - - // Server::DrainManager - MOCK_METHOD(bool, drainClose, (), (const)); - MOCK_METHOD(bool, draining, (), (const)); - MOCK_METHOD(void, startDrainSequence, (std::function completion)); - MOCK_METHOD(void, startParentShutdownSequence, ()); - - std::function drain_sequence_completion_; -}; - -class MockWatchDog : public WatchDog { -public: - MockWatchDog(); - ~MockWatchDog() override; - - // Server::WatchDog - MOCK_METHOD(void, startWatchdog, (Event::Dispatcher & dispatcher)); - MOCK_METHOD(void, touch, ()); - MOCK_METHOD(Thread::ThreadId, threadId, (), (const)); - MOCK_METHOD(MonotonicTime, lastTouchTime, (), (const)); -}; - -class MockGuardDog : public GuardDog { -public: - MockGuardDog(); - ~MockGuardDog() override; - - // Server::GuardDog - MOCK_METHOD(WatchDogSharedPtr, createWatchDog, - (Thread::ThreadId thread_id, const std::string& thread_name)); - MOCK_METHOD(void, stopWatching, (WatchDogSharedPtr wd)); - - std::shared_ptr watch_dog_; -}; - -class MockHotRestart : public HotRestart { -public: - MockHotRestart(); - ~MockHotRestart() override; - - // Server::HotRestart - MOCK_METHOD(void, drainParentListeners, ()); - MOCK_METHOD(int, duplicateParentListenSocket, (const std::string& address)); - MOCK_METHOD(std::unique_ptr, getParentStats, ()); - MOCK_METHOD(void, initialize, (Event::Dispatcher & dispatcher, Server::Instance& server)); - MOCK_METHOD(void, sendParentAdminShutdownRequest, (time_t & original_start_time)); - MOCK_METHOD(void, sendParentTerminateRequest, ()); - MOCK_METHOD(ServerStatsFromParent, mergeParentStatsIfAny, (Stats::StoreRoot & stats_store)); - MOCK_METHOD(void, shutdown, ()); - MOCK_METHOD(uint32_t, baseId, ()); - MOCK_METHOD(std::string, version, ()); - MOCK_METHOD(Thread::BasicLockable&, logLock, ()); - MOCK_METHOD(Thread::BasicLockable&, accessLogLock, ()); - MOCK_METHOD(Stats::Allocator&, statsAllocator, ()); - -private: - Stats::TestSymbolTable symbol_table_; - Thread::MutexBasicLockable log_lock_; - Thread::MutexBasicLockable access_log_lock_; - Stats::AllocatorImpl stats_allocator_; -}; - -class MockListenerComponentFactory : public ListenerComponentFactory { -public: - MockListenerComponentFactory(); - ~MockListenerComponentFactory() override; - - DrainManagerPtr - createDrainManager(envoy::config::listener::v3::Listener::DrainType drain_type) override { - return DrainManagerPtr{createDrainManager_(drain_type)}; - } - LdsApiPtr createLdsApi(const envoy::config::core::v3::ConfigSource& lds_config) override { - return LdsApiPtr{createLdsApi_(lds_config)}; - } - - MOCK_METHOD(LdsApi*, createLdsApi_, (const envoy::config::core::v3::ConfigSource& lds_config)); - MOCK_METHOD(std::vector, createNetworkFilterFactoryList, - (const Protobuf::RepeatedPtrField& filters, - Configuration::FilterChainFactoryContext& filter_chain_factory_context)); - MOCK_METHOD(std::vector, createListenerFilterFactoryList, - (const Protobuf::RepeatedPtrField&, - Configuration::ListenerFactoryContext& context)); - MOCK_METHOD(std::vector, createUdpListenerFilterFactoryList, - (const Protobuf::RepeatedPtrField&, - Configuration::ListenerFactoryContext& context)); - MOCK_METHOD(Network::SocketSharedPtr, createListenSocket, - (Network::Address::InstanceConstSharedPtr address, Network::Socket::Type socket_type, - const Network::Socket::OptionsSharedPtr& options, - const ListenSocketCreationParams& params)); - MOCK_METHOD(DrainManager*, createDrainManager_, - (envoy::config::listener::v3::Listener::DrainType drain_type)); - MOCK_METHOD(uint64_t, nextListenerTag, ()); - - std::shared_ptr socket_; -}; - -class MockListenerManager : public ListenerManager { -public: - MockListenerManager(); - ~MockListenerManager() override; - - MOCK_METHOD(bool, addOrUpdateListener, - (const envoy::config::listener::v3::Listener& config, const std::string& version_info, - bool modifiable)); - MOCK_METHOD(void, createLdsApi, (const envoy::config::core::v3::ConfigSource& lds_config)); - MOCK_METHOD(std::vector>, listeners, ()); - MOCK_METHOD(uint64_t, numConnections, (), (const)); - MOCK_METHOD(bool, removeListener, (const std::string& listener_name)); - MOCK_METHOD(void, startWorkers, (GuardDog & guard_dog)); - MOCK_METHOD(void, stopListeners, (StopListenersType listeners_type)); - MOCK_METHOD(void, stopWorkers, ()); - MOCK_METHOD(void, beginListenerUpdate, ()); - MOCK_METHOD(void, endListenerUpdate, (ListenerManager::FailureStates &&)); - MOCK_METHOD(ApiListenerOptRef, apiListener, ()); -}; - -class MockServerLifecycleNotifier : public ServerLifecycleNotifier { -public: - MockServerLifecycleNotifier(); - ~MockServerLifecycleNotifier() override; - - MOCK_METHOD(ServerLifecycleNotifier::HandlePtr, registerCallback, (Stage, StageCallback)); - MOCK_METHOD(ServerLifecycleNotifier::HandlePtr, registerCallback, - (Stage, StageCallbackWithCompletion)); -}; - -class MockWorkerFactory : public WorkerFactory { -public: - MockWorkerFactory(); - ~MockWorkerFactory() override; - - // Server::WorkerFactory - WorkerPtr createWorker(OverloadManager&, const std::string&) override { - return WorkerPtr{createWorker_()}; - } - - MOCK_METHOD(Worker*, createWorker_, ()); -}; - -class MockWorker : public Worker { -public: - MockWorker(); - ~MockWorker() override; - - void callAddCompletion(bool success) { - EXPECT_NE(nullptr, add_listener_completion_); - add_listener_completion_(success); - add_listener_completion_ = nullptr; - } - - void callRemovalCompletion() { - EXPECT_NE(nullptr, remove_listener_completion_); - remove_listener_completion_(); - remove_listener_completion_ = nullptr; - } - - void callDrainFilterChainsComplete() { - EXPECT_NE(nullptr, remove_filter_chains_completion_); - remove_filter_chains_completion_(); - remove_filter_chains_completion_ = nullptr; - } - - // Server::Worker - MOCK_METHOD(void, addListener, - (absl::optional overridden_listener, Network::ListenerConfig& listener, - AddListenerCompletion completion)); - MOCK_METHOD(uint64_t, numConnections, (), (const)); - MOCK_METHOD(void, removeListener, - (Network::ListenerConfig & listener, std::function completion)); - MOCK_METHOD(void, start, (GuardDog & guard_dog)); - MOCK_METHOD(void, initializeStats, (Stats::Scope & scope)); - MOCK_METHOD(void, stop, ()); - MOCK_METHOD(void, stopListener, - (Network::ListenerConfig & listener, std::function completion)); - MOCK_METHOD(void, removeFilterChains, - (uint64_t listener_tag, const std::list& filter_chains, - std::function completion)); - - AddListenerCompletion add_listener_completion_; - std::function remove_listener_completion_; - std::function remove_filter_chains_completion_; -}; - -class MockOverloadManager : public OverloadManager { -public: - MockOverloadManager(); - ~MockOverloadManager() override; - - // OverloadManager - MOCK_METHOD(void, start, ()); - MOCK_METHOD(bool, registerForAction, - (const std::string& action, Event::Dispatcher& dispatcher, - OverloadActionCb callback)); - MOCK_METHOD(ThreadLocalOverloadState&, getThreadLocalOverloadState, ()); - - ThreadLocalOverloadState overload_state_; -}; - -class MockInstance : public Instance { -public: - MockInstance(); - ~MockInstance() override; - - Secret::SecretManager& secretManager() override { return *(secret_manager_.get()); } - - MOCK_METHOD(Admin&, admin, ()); - MOCK_METHOD(Api::Api&, api, ()); - MOCK_METHOD(Upstream::ClusterManager&, clusterManager, ()); - MOCK_METHOD(Ssl::ContextManager&, sslContextManager, ()); - MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); - MOCK_METHOD(Network::DnsResolverSharedPtr, dnsResolver, ()); - MOCK_METHOD(void, drainListeners, ()); - MOCK_METHOD(DrainManager&, drainManager, ()); - MOCK_METHOD(AccessLog::AccessLogManager&, accessLogManager, ()); - MOCK_METHOD(void, failHealthcheck, (bool fail)); - MOCK_METHOD(void, exportStatsToChild, (envoy::HotRestartMessage::Reply::Stats*)); - MOCK_METHOD(bool, healthCheckFailed, ()); - MOCK_METHOD(HotRestart&, hotRestart, ()); - MOCK_METHOD(Init::Manager&, initManager, ()); - MOCK_METHOD(ServerLifecycleNotifier&, lifecycleNotifier, ()); - MOCK_METHOD(ListenerManager&, listenerManager, ()); - MOCK_METHOD(Envoy::MutexTracer*, mutexTracer, ()); - MOCK_METHOD(const Options&, options, ()); - MOCK_METHOD(OverloadManager&, overloadManager, ()); - MOCK_METHOD(Runtime::RandomGenerator&, random, ()); - MOCK_METHOD(Runtime::Loader&, runtime, ()); - MOCK_METHOD(void, shutdown, ()); - MOCK_METHOD(bool, isShutdown, ()); - MOCK_METHOD(void, shutdownAdmin, ()); - MOCK_METHOD(Singleton::Manager&, singletonManager, ()); - MOCK_METHOD(time_t, startTimeCurrentEpoch, ()); - MOCK_METHOD(time_t, startTimeFirstEpoch, ()); - MOCK_METHOD(Stats::Store&, stats, ()); - MOCK_METHOD(Grpc::Context&, grpcContext, ()); - MOCK_METHOD(Http::Context&, httpContext, ()); - MOCK_METHOD(ProcessContextOptRef, processContext, ()); - MOCK_METHOD(ThreadLocal::Instance&, threadLocal, ()); - MOCK_METHOD(const LocalInfo::LocalInfo&, localInfo, (), (const)); - MOCK_METHOD(std::chrono::milliseconds, statsFlushInterval, (), (const)); - MOCK_METHOD(void, flushStats, ()); - MOCK_METHOD(ProtobufMessage::ValidationContext&, messageValidationContext, ()); - MOCK_METHOD(Configuration::ServerFactoryContext&, serverFactoryContext, ()); - MOCK_METHOD(Configuration::TransportSocketFactoryContext&, transportSocketFactoryContext, ()); - - void setDefaultTracingConfig(const envoy::config::trace::v3::Tracing& tracing_config) override { - http_context_.setDefaultTracingConfig(tracing_config); - } - - TimeSource& timeSource() override { return time_system_; } - - NiceMock stats_store_; - testing::NiceMock thread_local_; - std::shared_ptr> dns_resolver_{ - new testing::NiceMock()}; - testing::NiceMock api_; - testing::NiceMock admin_; - Event::GlobalTimeSystem time_system_; - std::unique_ptr secret_manager_; - testing::NiceMock cluster_manager_; - Thread::MutexBasicLockable access_log_lock_; - testing::NiceMock runtime_loader_; - Extensions::TransportSockets::Tls::ContextManagerImpl ssl_context_manager_; - testing::NiceMock dispatcher_; - testing::NiceMock drain_manager_; - testing::NiceMock access_log_manager_; - testing::NiceMock hot_restart_; - testing::NiceMock options_; - testing::NiceMock random_; - testing::NiceMock lifecycle_notifier_; - testing::NiceMock local_info_; - testing::NiceMock init_manager_; - testing::NiceMock listener_manager_; - testing::NiceMock overload_manager_; - Singleton::ManagerPtr singleton_manager_; - Grpc::ContextImpl grpc_context_; - Http::ContextImpl http_context_; - testing::NiceMock validation_context_; - std::shared_ptr> - server_factory_context_; - std::shared_ptr> - transport_socket_factory_context_; -}; - -namespace Configuration { - -class MockMain : public Main { -public: - MockMain() : MockMain(0, 0, 0, 0) {} - MockMain(int wd_miss, int wd_megamiss, int wd_kill, int wd_multikill); - ~MockMain() override; - - MOCK_METHOD(Upstream::ClusterManager*, clusterManager, ()); - MOCK_METHOD(std::list&, statsSinks, ()); - MOCK_METHOD(std::chrono::milliseconds, statsFlushInterval, (), (const)); - MOCK_METHOD(std::chrono::milliseconds, wdMissTimeout, (), (const)); - MOCK_METHOD(std::chrono::milliseconds, wdMegaMissTimeout, (), (const)); - MOCK_METHOD(std::chrono::milliseconds, wdKillTimeout, (), (const)); - MOCK_METHOD(std::chrono::milliseconds, wdMultiKillTimeout, (), (const)); - - std::chrono::milliseconds wd_miss_; - std::chrono::milliseconds wd_megamiss_; - std::chrono::milliseconds wd_kill_; - std::chrono::milliseconds wd_multikill_; -}; - -class MockServerFactoryContext : public virtual ServerFactoryContext { -public: - MockServerFactoryContext(); - ~MockServerFactoryContext() override; - - MOCK_METHOD(Upstream::ClusterManager&, clusterManager, ()); - MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); - MOCK_METHOD(const Network::DrainDecision&, drainDecision, ()); - MOCK_METHOD(const LocalInfo::LocalInfo&, localInfo, (), (const)); - MOCK_METHOD(Envoy::Runtime::RandomGenerator&, random, ()); - MOCK_METHOD(Envoy::Runtime::Loader&, runtime, ()); - MOCK_METHOD(Stats::Scope&, scope, ()); - MOCK_METHOD(Singleton::Manager&, singletonManager, ()); - MOCK_METHOD(ThreadLocal::Instance&, threadLocal, ()); - MOCK_METHOD(Server::Admin&, admin, ()); - MOCK_METHOD(TimeSource&, timeSource, ()); - Event::TestTimeSystem& timeSystem() { return time_system_; } - MOCK_METHOD(ProtobufMessage::ValidationContext&, messageValidationContext, ()); - MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); - MOCK_METHOD(Api::Api&, api, ()); - Grpc::Context& grpcContext() override { return grpc_context_; } - MOCK_METHOD(Server::DrainManager&, drainManager, ()); - MOCK_METHOD(Init::Manager&, initManager, ()); - MOCK_METHOD(ServerLifecycleNotifier&, lifecycleNotifier, ()); - - testing::NiceMock cluster_manager_; - testing::NiceMock dispatcher_; - testing::NiceMock drain_manager_; - testing::NiceMock local_info_; - testing::NiceMock random_; - testing::NiceMock runtime_loader_; - testing::NiceMock scope_; - testing::NiceMock thread_local_; - testing::NiceMock validation_context_; - Singleton::ManagerPtr singleton_manager_; - testing::NiceMock admin_; - Event::GlobalTimeSystem time_system_; - testing::NiceMock api_; - Grpc::ContextImpl grpc_context_; -}; - -class MockFactoryContext : public virtual FactoryContext { -public: - MockFactoryContext(); - ~MockFactoryContext() override; - - MOCK_METHOD(ServerFactoryContext&, getServerFactoryContext, (), (const)); - MOCK_METHOD(TransportSocketFactoryContext&, getTransportSocketFactoryContext, (), (const)); - MOCK_METHOD(AccessLog::AccessLogManager&, accessLogManager, ()); - MOCK_METHOD(Upstream::ClusterManager&, clusterManager, ()); - MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); - MOCK_METHOD(const Network::DrainDecision&, drainDecision, ()); - MOCK_METHOD(bool, healthCheckFailed, ()); - MOCK_METHOD(Init::Manager&, initManager, ()); - MOCK_METHOD(ServerLifecycleNotifier&, lifecycleNotifier, ()); - MOCK_METHOD(Envoy::Runtime::RandomGenerator&, random, ()); - MOCK_METHOD(Envoy::Runtime::Loader&, runtime, ()); - MOCK_METHOD(Stats::Scope&, scope, ()); - MOCK_METHOD(Singleton::Manager&, singletonManager, ()); - MOCK_METHOD(OverloadManager&, overloadManager, ()); - MOCK_METHOD(ThreadLocal::Instance&, threadLocal, ()); - MOCK_METHOD(Server::Admin&, admin, ()); - MOCK_METHOD(Stats::Scope&, listenerScope, ()); - MOCK_METHOD(const LocalInfo::LocalInfo&, localInfo, (), (const)); - MOCK_METHOD(const envoy::config::core::v3::Metadata&, listenerMetadata, (), (const)); - MOCK_METHOD(envoy::config::core::v3::TrafficDirection, direction, (), (const)); - MOCK_METHOD(TimeSource&, timeSource, ()); - Event::TestTimeSystem& timeSystem() { return time_system_; } - Grpc::Context& grpcContext() override { return grpc_context_; } - Http::Context& httpContext() override { return http_context_; } - MOCK_METHOD(ProcessContextOptRef, processContext, ()); - MOCK_METHOD(ProtobufMessage::ValidationContext&, messageValidationContext, ()); - MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); - MOCK_METHOD(Api::Api&, api, ()); - - testing::NiceMock server_factory_context_; - testing::NiceMock access_log_manager_; - testing::NiceMock cluster_manager_; - testing::NiceMock dispatcher_; - testing::NiceMock drain_manager_; - testing::NiceMock init_manager_; - testing::NiceMock lifecycle_notifier_; - testing::NiceMock local_info_; - testing::NiceMock random_; - testing::NiceMock runtime_loader_; - testing::NiceMock scope_; - testing::NiceMock thread_local_; - Singleton::ManagerPtr singleton_manager_; - testing::NiceMock admin_; - Stats::IsolatedStoreImpl listener_scope_; - Event::GlobalTimeSystem time_system_; - testing::NiceMock validation_context_; - testing::NiceMock overload_manager_; - Grpc::ContextImpl grpc_context_; - Http::ContextImpl http_context_; - testing::NiceMock api_; -}; - -class MockTransportSocketFactoryContext : public TransportSocketFactoryContext { -public: - MockTransportSocketFactoryContext(); - ~MockTransportSocketFactoryContext() override; - - Secret::SecretManager& secretManager() override { return *(secret_manager_.get()); } - - MOCK_METHOD(Server::Admin&, admin, ()); - MOCK_METHOD(Ssl::ContextManager&, sslContextManager, ()); - MOCK_METHOD(Stats::Scope&, scope, ()); - MOCK_METHOD(Upstream::ClusterManager&, clusterManager, ()); - MOCK_METHOD(const LocalInfo::LocalInfo&, localInfo, (), (const)); - MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); - MOCK_METHOD(Envoy::Runtime::RandomGenerator&, random, ()); - MOCK_METHOD(Stats::Store&, stats, ()); - MOCK_METHOD(Init::Manager&, initManager, ()); - MOCK_METHOD(Singleton::Manager&, singletonManager, ()); - MOCK_METHOD(ThreadLocal::SlotAllocator&, threadLocal, ()); - MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); - MOCK_METHOD(Api::Api&, api, ()); - - testing::NiceMock cluster_manager_; - testing::NiceMock api_; - testing::NiceMock config_tracker_; - std::unique_ptr secret_manager_; -}; - -class MockListenerFactoryContext : public MockFactoryContext, public ListenerFactoryContext { -public: - MockListenerFactoryContext(); - ~MockListenerFactoryContext() override; - - const Network::ListenerConfig& listenerConfig() const override { return listener_config_; } - MOCK_METHOD(const Network::ListenerConfig&, listenerConfig_, (), (const)); - - Network::MockListenerConfig listener_config_; -}; - -class MockHealthCheckerFactoryContext : public virtual HealthCheckerFactoryContext { -public: - MockHealthCheckerFactoryContext(); - ~MockHealthCheckerFactoryContext() override; - - MOCK_METHOD(Upstream::Cluster&, cluster, ()); - MOCK_METHOD(Event::Dispatcher&, dispatcher, ()); - MOCK_METHOD(Envoy::Runtime::RandomGenerator&, random, ()); - MOCK_METHOD(Envoy::Runtime::Loader&, runtime, ()); - MOCK_METHOD(Upstream::HealthCheckEventLogger*, eventLogger_, ()); - MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); - MOCK_METHOD(Api::Api&, api, ()); - Upstream::HealthCheckEventLoggerPtr eventLogger() override { - return Upstream::HealthCheckEventLoggerPtr(eventLogger_()); - } - - testing::NiceMock cluster_; - testing::NiceMock dispatcher_; - testing::NiceMock random_; - testing::NiceMock runtime_; - testing::NiceMock* event_logger_{}; - testing::NiceMock api_{}; -}; - -class MockFilterChainFactoryContext : public MockFactoryContext, public FilterChainFactoryContext { -public: - MockFilterChainFactoryContext(); - ~MockFilterChainFactoryContext() override; -}; - -class MockTracerFactory : public TracerFactory { -public: - explicit MockTracerFactory(const std::string& name); - ~MockTracerFactory() override; - - std::string name() const override { return name_; } - - MOCK_METHOD(ProtobufTypes::MessagePtr, createEmptyConfigProto, ()); - MOCK_METHOD(Tracing::HttpTracerSharedPtr, createHttpTracer, - (const Protobuf::Message& config, TracerFactoryContext& context)); - -private: - std::string name_; -}; - -class MockTracerFactoryContext : public TracerFactoryContext { -public: - MockTracerFactoryContext(); - ~MockTracerFactoryContext() override; - - MOCK_METHOD(ServerFactoryContext&, serverFactoryContext, ()); - MOCK_METHOD(ProtobufMessage::ValidationVisitor&, messageValidationVisitor, ()); - - testing::NiceMock server_factory_context_; -}; - -class MockBootstrapExtensionFactory : public BootstrapExtensionFactory { -public: - MockBootstrapExtensionFactory(); - ~MockBootstrapExtensionFactory() override; - - MOCK_METHOD(BootstrapExtensionPtr, createBootstrapExtension, - (const Protobuf::Message&, Configuration::ServerFactoryContext&), (override)); - MOCK_METHOD(ProtobufTypes::MessagePtr, createEmptyConfigProto, (), (override)); - MOCK_METHOD(std::string, name, (), (const, override)); -}; - -} // namespace Configuration -} // namespace Server -} // namespace Envoy +#include "drain_manager.h" +#include "health_checker_factory_context.h" +#include "listener_factory_context.h" +#include "options.h" +#include "tracer_factory.h" +#include "worker.h" +#include "admin_stream.h" +#include "factory_context.h" +#include "hot_restart.h" +#include "listener_manager.h" +#include "overload_manager.h" +#include "transport_socket_factory_context.h" +#include "bootstrap_extension_factory.h" +#include "filter_chain_factory_context.h" +#include "instance.h" +#include "main.h" +#include "server_lifecycle_notifier.h" +#include "watch_dog.h" +#include "guard_dog.h" +#include "listener_component_factory.h" +#include "tracer_factory_context.h" +#include "worker_factory.h" diff --git a/test/mocks/server/tracer_factory_context.h b/test/mocks/server/tracer_factory_context.h index 8a561c5b4131..c091fec565fa 100644 --- a/test/mocks/server/tracer_factory_context.h +++ b/test/mocks/server/tracer_factory_context.h @@ -5,58 +5,10 @@ #include #include -#include "envoy/common/mutex_tracer.h" -#include "envoy/config/bootstrap/v3/bootstrap.pb.h" -#include "envoy/config/core/v3/base.pb.h" -#include "envoy/config/core/v3/config_source.pb.h" -#include "envoy/config/listener/v3/listener.pb.h" -#include "envoy/config/listener/v3/listener_components.pb.h" -#include "envoy/protobuf/message_validator.h" -#include "envoy/server/admin.h" -#include "envoy/server/bootstrap_extension_config.h" #include "envoy/server/configuration.h" -#include "envoy/server/drain_manager.h" -#include "envoy/server/filter_config.h" -#include "envoy/server/health_checker_config.h" -#include "envoy/server/instance.h" -#include "envoy/server/options.h" -#include "envoy/server/overload_manager.h" -#include "envoy/server/tracer_config.h" -#include "envoy/server/transport_socket_config.h" -#include "envoy/server/worker.h" -#include "envoy/ssl/context_manager.h" -#include "envoy/stats/scope.h" -#include "envoy/thread/thread.h" -#include "common/grpc/context_impl.h" -#include "common/http/context_impl.h" -#include "common/secret/secret_manager_impl.h" -#include "common/stats/fake_symbol_table_impl.h" -#include "extensions/transport_sockets/tls/context_manager_impl.h" - -#include "test/mocks/access_log/mocks.h" -#include "test/mocks/api/mocks.h" -#include "test/mocks/event/mocks.h" -#include "test/mocks/http/mocks.h" -#include "test/mocks/init/mocks.h" -#include "test/mocks/local_info/mocks.h" -#include "test/mocks/network/mocks.h" -#include "test/mocks/protobuf/mocks.h" -#include "test/mocks/router/mocks.h" -#include "test/mocks/runtime/mocks.h" -#include "test/mocks/secret/mocks.h" -#include "test/mocks/stats/mocks.h" -#include "test/mocks/thread_local/mocks.h" -#include "test/mocks/tracing/mocks.h" -#include "test/mocks/upstream/mocks.h" -#include "test/test_common/test_time_system.h" - -#include "absl/strings/string_view.h" -#include "admin.h" -#include "config_tracker.h" #include "gmock/gmock.h" -#include "spdlog/spdlog.h" #include "instance.h" #include "tracer_factory.h" From ba1be16c1b757a41319974f7ab8c3f7d0a86c0ec Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 29 Jun 2020 06:44:37 +0000 Subject: [PATCH 03/17] fix duplicate symbol error Signed-off-by: Muge Chen --- test/mocks/server/instance.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/mocks/server/instance.cc b/test/mocks/server/instance.cc index 4992c3ccf9a6..1478822eee00 100644 --- a/test/mocks/server/instance.cc +++ b/test/mocks/server/instance.cc @@ -57,19 +57,34 @@ MockInstance::MockInstance() MockInstance::~MockInstance() = default; + namespace Configuration { -MockTransportSocketFactoryContext::MockTransportSocketFactoryContext() - : secret_manager_(std::make_unique(config_tracker_)) { + +MockServerFactoryContext::MockServerFactoryContext() + : singleton_manager_(new Singleton::ManagerImpl(Thread::threadFactoryForTest())), + grpc_context_(scope_.symbolTable()) { ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); + ON_CALL(*this, dispatcher()).WillByDefault(ReturnRef(dispatcher_)); + ON_CALL(*this, drainDecision()).WillByDefault(ReturnRef(drain_manager_)); + ON_CALL(*this, localInfo()).WillByDefault(ReturnRef(local_info_)); + ON_CALL(*this, random()).WillByDefault(ReturnRef(random_)); + ON_CALL(*this, runtime()).WillByDefault(ReturnRef(runtime_loader_)); + ON_CALL(*this, scope()).WillByDefault(ReturnRef(scope_)); + ON_CALL(*this, singletonManager()).WillByDefault(ReturnRef(*singleton_manager_)); + ON_CALL(*this, threadLocal()).WillByDefault(ReturnRef(thread_local_)); + ON_CALL(*this, admin()).WillByDefault(ReturnRef(admin_)); ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); + ON_CALL(*this, timeSource()).WillByDefault(ReturnRef(time_system_)); + ON_CALL(*this, messageValidationContext()).WillByDefault(ReturnRef(validation_context_)); ON_CALL(*this, messageValidationVisitor()) .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); + ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); + ON_CALL(*this, drainManager()).WillByDefault(ReturnRef(drain_manager_)); } +MockServerFactoryContext::~MockServerFactoryContext() = default; -MockTransportSocketFactoryContext::~MockTransportSocketFactoryContext() = default; - } From e022b7498f44809ed8161b66c3008ecf59e42c6f Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 29 Jun 2020 06:59:52 +0000 Subject: [PATCH 04/17] fix format Signed-off-by: Muge Chen --- test/mocks/server/BUILD | 109 +++++++++--------- test/mocks/server/admin_stream.cc | 6 +- test/mocks/server/admin_stream.h | 5 +- .../server/bootstrap_extension_factory.cc | 8 +- .../server/bootstrap_extension_factory.h | 6 +- test/mocks/server/drain_manager.cc | 6 +- test/mocks/server/drain_manager.h | 5 +- test/mocks/server/factory_context.cc | 9 +- test/mocks/server/factory_context.h | 14 +-- .../server/filter_chain_factory_context.cc | 8 +- .../server/filter_chain_factory_context.h | 7 +- test/mocks/server/guard_dog.cc | 8 +- test/mocks/server/guard_dog.h | 7 +- .../server/health_checker_factory_context.cc | 10 +- .../server/health_checker_factory_context.h | 7 +- test/mocks/server/hot_restart.cc | 6 +- test/mocks/server/hot_restart.h | 5 +- test/mocks/server/instance.cc | 12 +- test/mocks/server/instance.h | 20 ++-- .../server/listener_component_factory.cc | 6 +- .../mocks/server/listener_component_factory.h | 8 +- test/mocks/server/listener_factory_context.cc | 8 +- test/mocks/server/listener_factory_context.h | 8 +- test/mocks/server/listener_manager.cc | 6 +- test/mocks/server/listener_manager.h | 5 +- test/mocks/server/main.cc | 9 +- test/mocks/server/main.h | 8 +- test/mocks/server/mocks.cc | 1 + test/mocks/server/mocks.h | 30 ++--- test/mocks/server/options.cc | 6 +- test/mocks/server/options.h | 4 +- test/mocks/server/overload_manager.cc | 7 +- test/mocks/server/overload_manager.h | 4 +- .../mocks/server/server_lifecycle_notifier.cc | 6 +- test/mocks/server/server_lifecycle_notifier.h | 4 +- test/mocks/server/tracer_factory.cc | 8 +- test/mocks/server/tracer_factory.h | 8 +- test/mocks/server/tracer_factory_context.cc | 9 +- test/mocks/server/tracer_factory_context.h | 9 +- .../transport_socket_factory_context.cc | 10 +- .../server/transport_socket_factory_context.h | 12 +- test/mocks/server/watch_dog.cc | 6 +- test/mocks/server/watch_dog.h | 4 +- test/mocks/server/worker.cc | 6 +- test/mocks/server/worker.h | 4 +- test/mocks/server/worker_factory.cc | 6 +- test/mocks/server/worker_factory.h | 6 +- 47 files changed, 204 insertions(+), 262 deletions(-) diff --git a/test/mocks/server/BUILD b/test/mocks/server/BUILD index 0b96d7a6f816..bc7bdb02448d 100644 --- a/test/mocks/server/BUILD +++ b/test/mocks/server/BUILD @@ -27,14 +27,13 @@ envoy_cc_mock( ], ) - envoy_cc_mock( name = "bootstrap_extension_factory_mocks", srcs = ["bootstrap_extension_factory.cc"], hdrs = ["bootstrap_extension_factory.h"], deps = [ "//include/envoy/server:bootstrap_extension_config_interface", - ] + ], ) envoy_cc_mock( @@ -43,9 +42,9 @@ envoy_cc_mock( hdrs = ["options.h"], deps = [ "//include/envoy/server:options_interface", - "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto", "@envoy_api//envoy/admin/v3:pkg_cc_proto", - ] + "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto", + ], ) envoy_cc_mock( @@ -55,7 +54,7 @@ envoy_cc_mock( deps = [ "//include/envoy/server:admin_interface", "//test/mocks/http:http_mocks", - ] + ], ) envoy_cc_mock( @@ -64,7 +63,7 @@ envoy_cc_mock( hdrs = ["drain_manager.h"], deps = [ "//include/envoy/server:drain_manager_interface", - ] + ], ) envoy_cc_mock( @@ -73,7 +72,7 @@ envoy_cc_mock( hdrs = ["watch_dog.h"], deps = [ "//include/envoy/server:watchdog_interface", - ] + ], ) envoy_cc_mock( @@ -83,7 +82,7 @@ envoy_cc_mock( deps = [ "//include/envoy/server:guarddog_interface", "//test/mocks/server:watch_dog_mocks", - ] + ], ) envoy_cc_mock( @@ -93,7 +92,7 @@ envoy_cc_mock( deps = [ "//include/envoy/server:instance_interface", "//test/mocks/stats:stats_mocks", - ] + ], ) envoy_cc_mock( @@ -101,12 +100,13 @@ envoy_cc_mock( srcs = ["listener_component_factory.cc"], hdrs = ["listener_component_factory.h"], deps = [ - "//include/envoy/server:listener_manager_interface", "//include/envoy/server:drain_manager_interface", + "//include/envoy/server:listener_manager_interface", "//test/mocks/network:network_mocks", - "@envoy_api//envoy/config/listener/v3:pkg_cc_proto", + "@envoy_api//envoy/admin/v3:pkg_cc_proto", "@envoy_api//envoy/config/core/v3:pkg_cc_proto", - ] + "@envoy_api//envoy/config/listener/v3:pkg_cc_proto", + ], ) envoy_cc_mock( @@ -115,7 +115,7 @@ envoy_cc_mock( hdrs = ["listener_manager.h"], deps = [ "//include/envoy/server:listener_manager_interface", - ] + ], ) envoy_cc_mock( @@ -124,7 +124,7 @@ envoy_cc_mock( hdrs = ["server_lifecycle_notifier.h"], deps = [ "//include/envoy/server:lifecycle_notifier_interface", - ] + ], ) envoy_cc_mock( @@ -134,7 +134,7 @@ envoy_cc_mock( deps = [ "//include/envoy/server:worker_interface", "//test/mocks/server:worker_mocks", - ] + ], ) envoy_cc_mock( @@ -143,7 +143,7 @@ envoy_cc_mock( hdrs = ["worker.h"], deps = [ "//include/envoy/server:worker_interface", - ] + ], ) envoy_cc_mock( @@ -152,7 +152,7 @@ envoy_cc_mock( hdrs = ["overload_manager.h"], deps = [ "//include/envoy/server:overload_manager_interface", - ] + ], ) envoy_cc_mock( @@ -177,19 +177,18 @@ envoy_cc_mock( "//test/mocks/router:router_mocks", "//test/mocks/runtime:runtime_mocks", "//test/mocks/secret:secret_mocks", - "//test/mocks/thread_local:thread_local_mocks", - "//test/mocks/tracing:tracing_mocks", - "//test/mocks/upstream:upstream_mocks", - "//test/mocks/server:admin_mocks", - "//test/mocks/server:listener_manager_mocks", - "//test/mocks/server:server_lifecycle_notifier_mocks", "//test/mocks/server:drain_manager_mocks", + "//test/mocks/server:hot_restart_mocks", + "//test/mocks/server:listener_manager_mocks", + "//test/mocks/server:options_mocks", "//test/mocks/server:overload_manager_mocks", + "//test/mocks/server:server_lifecycle_notifier_mocks", "//test/mocks/server:transport_socket_factory_context_mocks", - "//test/mocks/server:options_mocks", - "//test/mocks/server:hot_restart_mocks", - ] + "//test/mocks/thread_local:thread_local_mocks", + "//test/mocks/tracing:tracing_mocks", + "//test/mocks/upstream:upstream_mocks", + ], ) envoy_cc_mock( @@ -197,9 +196,9 @@ envoy_cc_mock( srcs = ["main.cc"], hdrs = ["main.h"], deps = [ - "//include/envoy/server:overload_manager_interface", "//include/envoy/server:configuration_interface", - ] + "//include/envoy/server:overload_manager_interface", + ], ) envoy_cc_mock( @@ -207,11 +206,11 @@ envoy_cc_mock( srcs = ["factory_context.cc"], hdrs = ["factory_context.h"], deps = [ - "//test/mocks/server:server_lifecycle_notifier_mocks", "//test/mocks/server:drain_manager_mocks", - "//test/mocks/server:overload_manager_mocks", "//test/mocks/server:instance_mocks", - ] + "//test/mocks/server:overload_manager_mocks", + "//test/mocks/server:server_lifecycle_notifier_mocks", + ], ) envoy_cc_mock( @@ -220,11 +219,11 @@ envoy_cc_mock( hdrs = ["transport_socket_factory_context.h"], deps = [ "//include/envoy/server:tracer_config_interface", + "//source/common/secret:secret_manager_impl_lib", + "//test/mocks/api:api_mocks", "//test/mocks/server:config_tracker_mocks", "//test/mocks/upstream:upstream_mocks", - "//test/mocks/api:api_mocks", - "//source/common/secret:secret_manager_impl_lib", - ] + ], ) envoy_cc_mock( @@ -234,7 +233,7 @@ envoy_cc_mock( deps = [ "//include/envoy/server:listener_manager_interface", "//test/mocks/server:factory_context_mocks", - ] + ], ) envoy_cc_mock( @@ -249,7 +248,7 @@ envoy_cc_mock( "//test/mocks/router:router_mocks", "//test/mocks/runtime:runtime_mocks", "//test/mocks/upstream:upstream_mocks", - ] + ], ) envoy_cc_mock( @@ -259,7 +258,7 @@ envoy_cc_mock( deps = [ "//include/envoy/server:filter_config_interface", "//test/mocks/server:factory_context_mocks", - ] + ], ) envoy_cc_mock( @@ -267,9 +266,9 @@ envoy_cc_mock( srcs = ["tracer_factory.cc"], hdrs = ["tracer_factory.h"], deps = [ - "//include/envoy/server:tracer_config_interface", "//include/envoy/protobuf:message_validator_interface", - ] + "//include/envoy/server:tracer_config_interface", + ], ) envoy_cc_mock( @@ -280,39 +279,37 @@ envoy_cc_mock( "//include/envoy/server:configuration_interface", "//test/mocks/server:instance_mocks", "//test/mocks/server:tracer_factory_mocks", - ] + ], ) - - envoy_cc_mock( name = "server_mocks", srcs = ["mocks.cc"], hdrs = ["mocks.h"], deps = [ "//test/mocks/server:admin_mocks", + "//test/mocks/server:admin_stream_mocks", + "//test/mocks/server:bootstrap_extension_factory_mocks", "//test/mocks/server:config_tracker_mocks", "//test/mocks/server:drain_manager_mocks", - "//test/mocks/server:health_checker_factory_context_mocks", - "//test/mocks/server:listener_factory_context_mocks", - "//test/mocks/server:options_mocks", - "//test/mocks/server:tracer_factory_mocks", - "//test/mocks/server:worker_mocks", - "//test/mocks/server:admin_stream_mocks", "//test/mocks/server:factory_context_mocks", - "//test/mocks/server:hot_restart_mocks", - "//test/mocks/server:listener_manager_mocks", - "//test/mocks/server:overload_manager_mocks", - "//test/mocks/server:transport_socket_factory_context_mocks", - "//test/mocks/server:bootstrap_extension_factory_mocks", "//test/mocks/server:filter_chain_factory_context_mocks", + "//test/mocks/server:guard_dog_mocks", + "//test/mocks/server:health_checker_factory_context_mocks", + "//test/mocks/server:hot_restart_mocks", "//test/mocks/server:instance_mocks", + "//test/mocks/server:listener_component_factory_mocks", + "//test/mocks/server:listener_factory_context_mocks", + "//test/mocks/server:listener_manager_mocks", "//test/mocks/server:main_mocks", + "//test/mocks/server:options_mocks", + "//test/mocks/server:overload_manager_mocks", "//test/mocks/server:server_lifecycle_notifier_mocks", - "//test/mocks/server:watch_dog_mocks", - "//test/mocks/server:guard_dog_mocks", - "//test/mocks/server:listener_component_factory_mocks", "//test/mocks/server:tracer_factory_context_mocks", + "//test/mocks/server:tracer_factory_mocks", + "//test/mocks/server:transport_socket_factory_context_mocks", + "//test/mocks/server:watch_dog_mocks", "//test/mocks/server:worker_factory_mocks", + "//test/mocks/server:worker_mocks", ], ) diff --git a/test/mocks/server/admin_stream.cc b/test/mocks/server/admin_stream.cc index 1c039069c847..8831de7a0245 100644 --- a/test/mocks/server/admin_stream.cc +++ b/test/mocks/server/admin_stream.cc @@ -18,8 +18,6 @@ MockAdminStream::MockAdminStream() = default; MockAdminStream::~MockAdminStream() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/admin_stream.h b/test/mocks/server/admin_stream.h index 5410037fb781..1c1900feeaaa 100644 --- a/test/mocks/server/admin_stream.h +++ b/test/mocks/server/admin_stream.h @@ -6,6 +6,7 @@ #include #include "envoy/server/admin.h" + #include "test/mocks/http/mocks.h" #include "absl/strings/string_view.h" @@ -27,6 +28,6 @@ class MockAdminStream : public AdminStream { (const)); MOCK_METHOD(Http::Http1StreamEncoderOptionsOptRef, http1StreamEncoderOptions, ()); }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/bootstrap_extension_factory.cc b/test/mocks/server/bootstrap_extension_factory.cc index 489dcffb6077..fa97c07280cd 100644 --- a/test/mocks/server/bootstrap_extension_factory.cc +++ b/test/mocks/server/bootstrap_extension_factory.cc @@ -1,6 +1,5 @@ #include "bootstrap_extension_factory.h" - namespace Envoy { namespace Server { namespace Configuration { @@ -8,9 +7,8 @@ MockBootstrapExtensionFactory::MockBootstrapExtensionFactory() = default; MockBootstrapExtensionFactory::~MockBootstrapExtensionFactory() = default; +} // namespace Configuration -} - -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/bootstrap_extension_factory.h b/test/mocks/server/bootstrap_extension_factory.h index 564bc5b2665f..d38f3c94a981 100644 --- a/test/mocks/server/bootstrap_extension_factory.h +++ b/test/mocks/server/bootstrap_extension_factory.h @@ -22,8 +22,8 @@ class MockBootstrapExtensionFactory : public BootstrapExtensionFactory { MOCK_METHOD(ProtobufTypes::MessagePtr, createEmptyConfigProto, (), (override)); MOCK_METHOD(std::string, name, (), (const, override)); }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/drain_manager.cc b/test/mocks/server/drain_manager.cc index 75f8ce8a74d8..32af0beb7785 100644 --- a/test/mocks/server/drain_manager.cc +++ b/test/mocks/server/drain_manager.cc @@ -20,8 +20,6 @@ MockDrainManager::MockDrainManager() { MockDrainManager::~MockDrainManager() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/drain_manager.h b/test/mocks/server/drain_manager.h index 01134be7eae3..278abe2c11b9 100644 --- a/test/mocks/server/drain_manager.h +++ b/test/mocks/server/drain_manager.h @@ -6,6 +6,7 @@ #include #include "envoy/server/drain_manager.h" + #include "gmock/gmock.h" namespace Envoy { @@ -23,6 +24,6 @@ class MockDrainManager : public DrainManager { std::function drain_sequence_completion_; }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/factory_context.cc b/test/mocks/server/factory_context.cc index 5484057c3db0..9e86e2faab7a 100644 --- a/test/mocks/server/factory_context.cc +++ b/test/mocks/server/factory_context.cc @@ -44,13 +44,10 @@ MockFactoryContext::MockFactoryContext() ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); } - MockFactoryContext::~MockFactoryContext() = default; +} // namespace Configuration +} // namespace Server -} - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/factory_context.h b/test/mocks/server/factory_context.h index a9cf35e526d9..89e50fdcdc07 100644 --- a/test/mocks/server/factory_context.h +++ b/test/mocks/server/factory_context.h @@ -12,13 +12,13 @@ #include "absl/strings/string_view.h" #include "admin.h" #include "config_tracker.h" +#include "drain_manager.h" #include "gmock/gmock.h" +#include "instance.h" +#include "overload_manager.h" +#include "server_lifecycle_notifier.h" #include "spdlog/spdlog.h" -#include "server_lifecycle_notifier.h" -#include "drain_manager.h" -#include "overload_manager.h" -#include "instance.h" namespace Envoy { namespace Server { namespace Configuration { @@ -78,6 +78,6 @@ class MockFactoryContext : public virtual FactoryContext { Http::ContextImpl http_context_; testing::NiceMock api_; }; -} -} -} +} // namespace Configuration +} // namespace Server +} // namespace Envoy diff --git a/test/mocks/server/filter_chain_factory_context.cc b/test/mocks/server/filter_chain_factory_context.cc index 2acd52988471..d2f7e3ed98fd 100644 --- a/test/mocks/server/filter_chain_factory_context.cc +++ b/test/mocks/server/filter_chain_factory_context.cc @@ -19,10 +19,8 @@ MockFilterChainFactoryContext::MockFilterChainFactoryContext() = default; MockFilterChainFactoryContext::~MockFilterChainFactoryContext() = default; +} // namespace Configuration +} // namespace Server -} - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/filter_chain_factory_context.h b/test/mocks/server/filter_chain_factory_context.h index 48c623dd6242..0b2095bd6b17 100644 --- a/test/mocks/server/filter_chain_factory_context.h +++ b/test/mocks/server/filter_chain_factory_context.h @@ -8,6 +8,7 @@ #include "envoy/server/filter_config.h" #include "factory_context.h" + namespace Envoy { namespace Server { namespace Configuration { @@ -16,8 +17,8 @@ class MockFilterChainFactoryContext : public MockFactoryContext, public FilterCh MockFilterChainFactoryContext(); ~MockFilterChainFactoryContext() override; }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/guard_dog.cc b/test/mocks/server/guard_dog.cc index fc1eb69a756d..7e72e83ab768 100644 --- a/test/mocks/server/guard_dog.cc +++ b/test/mocks/server/guard_dog.cc @@ -7,11 +7,11 @@ using testing::_; using testing::Invoke; +using testing::NiceMock; using testing::Return; using testing::ReturnPointee; using testing::ReturnRef; using testing::SaveArg; -using testing::NiceMock; namespace Envoy { namespace Server { @@ -21,8 +21,6 @@ MockGuardDog::MockGuardDog() : watch_dog_(new NiceMock()) { MockGuardDog::~MockGuardDog() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/guard_dog.h b/test/mocks/server/guard_dog.h index 920f1fd298e1..0c5ad2f0e28c 100644 --- a/test/mocks/server/guard_dog.h +++ b/test/mocks/server/guard_dog.h @@ -2,9 +2,8 @@ #include "envoy/server/guarddog.h" -#include "watch_dog.h" - #include "gmock/gmock.h" +#include "watch_dog.h" namespace Envoy { namespace Server { @@ -20,6 +19,6 @@ class MockGuardDog : public GuardDog { std::shared_ptr watch_dog_; }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/health_checker_factory_context.cc b/test/mocks/server/health_checker_factory_context.cc index 8db55f9b8098..ce1005ec4daf 100644 --- a/test/mocks/server/health_checker_factory_context.cc +++ b/test/mocks/server/health_checker_factory_context.cc @@ -2,7 +2,6 @@ #include - #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -28,13 +27,10 @@ MockHealthCheckerFactoryContext::MockHealthCheckerFactoryContext() { ON_CALL(*this, api()).WillByDefault(ReturnRef(api_)); } - MockHealthCheckerFactoryContext::~MockHealthCheckerFactoryContext() = default; +} // namespace Configuration +} // namespace Server -} - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/health_checker_factory_context.h b/test/mocks/server/health_checker_factory_context.h index 1e7b602ba83c..cb1c64eaeac0 100644 --- a/test/mocks/server/health_checker_factory_context.h +++ b/test/mocks/server/health_checker_factory_context.h @@ -7,7 +7,6 @@ #include "envoy/server/health_checker_config.h" - #include "test/mocks/api/mocks.h" #include "test/mocks/event/mocks.h" #include "test/mocks/protobuf/mocks.h" @@ -43,8 +42,8 @@ class MockHealthCheckerFactoryContext : public virtual HealthCheckerFactoryConte testing::NiceMock* event_logger_{}; testing::NiceMock api_{}; }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/hot_restart.cc b/test/mocks/server/hot_restart.cc index 3d1992848658..07e50121046e 100644 --- a/test/mocks/server/hot_restart.cc +++ b/test/mocks/server/hot_restart.cc @@ -22,8 +22,6 @@ MockHotRestart::MockHotRestart() : stats_allocator_(*symbol_table_) { MockHotRestart::~MockHotRestart() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/hot_restart.h b/test/mocks/server/hot_restart.h index e2b31214e0e9..a73ae73267dd 100644 --- a/test/mocks/server/hot_restart.h +++ b/test/mocks/server/hot_restart.h @@ -9,7 +9,6 @@ #include "test/mocks/stats/mocks.h" - #include "gmock/gmock.h" namespace Envoy { @@ -40,6 +39,6 @@ class MockHotRestart : public HotRestart { Thread::MutexBasicLockable access_log_lock_; Stats::AllocatorImpl stats_allocator_; }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/instance.cc b/test/mocks/server/instance.cc index 1478822eee00..b9c9adf38db6 100644 --- a/test/mocks/server/instance.cc +++ b/test/mocks/server/instance.cc @@ -54,13 +54,10 @@ MockInstance::MockInstance() .WillByDefault(ReturnRef(*transport_socket_factory_context_)); } - MockInstance::~MockInstance() = default; - namespace Configuration { - MockServerFactoryContext::MockServerFactoryContext() : singleton_manager_(new Singleton::ManagerImpl(Thread::threadFactoryForTest())), grpc_context_(scope_.symbolTable()) { @@ -84,11 +81,8 @@ MockServerFactoryContext::MockServerFactoryContext() } MockServerFactoryContext::~MockServerFactoryContext() = default; +} // namespace Configuration +} // namespace Server -} - - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/instance.h b/test/mocks/server/instance.h index 4b4bd76fbc7c..2ca51ebe348e 100644 --- a/test/mocks/server/instance.h +++ b/test/mocks/server/instance.h @@ -10,6 +10,7 @@ #include "common/grpc/context_impl.h" #include "common/http/context_impl.h" #include "common/stats/fake_symbol_table_impl.h" + #include "extensions/transport_sockets/tls/context_manager_impl.h" #include "test/mocks/access_log/mocks.h" @@ -27,16 +28,16 @@ #include "test/mocks/tracing/mocks.h" #include "test/mocks/upstream/mocks.h" +#include "admin.h" +#include "drain_manager.h" #include "gmock/gmock.h" - +#include "hot_restart.h" #include "listener_manager.h" -#include "server_lifecycle_notifier.h" -#include "drain_manager.h" +#include "options.h" #include "overload_manager.h" -#include "admin.h" +#include "server_lifecycle_notifier.h" #include "transport_socket_factory_context.h" -#include "options.h" -#include "hot_restart.h" + namespace Envoy { namespace Server { namespace Configuration { @@ -128,7 +129,6 @@ class MockInstance : public Instance { transport_socket_factory_context_; }; - namespace Configuration { class MockServerFactoryContext : public virtual ServerFactoryContext { public: @@ -170,8 +170,8 @@ class MockServerFactoryContext : public virtual ServerFactoryContext { testing::NiceMock api_; Grpc::ContextImpl grpc_context_; }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/listener_component_factory.cc b/test/mocks/server/listener_component_factory.cc index c46faf064516..e5c42ade62c7 100644 --- a/test/mocks/server/listener_component_factory.cc +++ b/test/mocks/server/listener_component_factory.cc @@ -33,8 +33,6 @@ MockListenerComponentFactory::MockListenerComponentFactory() MockListenerComponentFactory::~MockListenerComponentFactory() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/listener_component_factory.h b/test/mocks/server/listener_component_factory.h index 0a0c9942ce7d..d01488999a96 100644 --- a/test/mocks/server/listener_component_factory.h +++ b/test/mocks/server/listener_component_factory.h @@ -5,9 +5,9 @@ #include #include -#include "envoy/server/listener_manager.h" -#include "envoy/server/drain_manager.h" #include "envoy/config/listener/v3/listener_components.pb.h" +#include "envoy/server/drain_manager.h" +#include "envoy/server/listener_manager.h" #include "test/mocks/network/mocks.h" @@ -48,6 +48,6 @@ class MockListenerComponentFactory : public ListenerComponentFactory { std::shared_ptr socket_; }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/listener_factory_context.cc b/test/mocks/server/listener_factory_context.cc index 604b0856eafb..a72e8d830431 100644 --- a/test/mocks/server/listener_factory_context.cc +++ b/test/mocks/server/listener_factory_context.cc @@ -17,10 +17,8 @@ MockListenerFactoryContext::MockListenerFactoryContext() = default; MockListenerFactoryContext::~MockListenerFactoryContext() = default; +} // namespace Configuration +} // namespace Server -} - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/listener_factory_context.h b/test/mocks/server/listener_factory_context.h index 391db5f178fc..1536f1e4b99a 100644 --- a/test/mocks/server/listener_factory_context.h +++ b/test/mocks/server/listener_factory_context.h @@ -7,9 +7,9 @@ #include "envoy/server/listener_manager.h" +#include "factory_context.h" #include "gmock/gmock.h" -#include "factory_context.h" namespace Envoy { namespace Server { namespace Configuration { @@ -23,8 +23,8 @@ class MockListenerFactoryContext : public MockFactoryContext, public ListenerFac Network::MockListenerConfig listener_config_; }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/listener_manager.cc b/test/mocks/server/listener_manager.cc index 9fadb32925aa..9fedc2c6825b 100644 --- a/test/mocks/server/listener_manager.cc +++ b/test/mocks/server/listener_manager.cc @@ -18,8 +18,6 @@ MockListenerManager::MockListenerManager() = default; MockListenerManager::~MockListenerManager() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/listener_manager.h b/test/mocks/server/listener_manager.h index dafc76315ae1..c1b68d0ea33b 100644 --- a/test/mocks/server/listener_manager.h +++ b/test/mocks/server/listener_manager.h @@ -7,7 +7,6 @@ #include "envoy/server/listener_manager.h" - #include "gmock/gmock.h" namespace Envoy { @@ -31,6 +30,6 @@ class MockListenerManager : public ListenerManager { MOCK_METHOD(void, endListenerUpdate, (ListenerManager::FailureStates &&)); MOCK_METHOD(ApiListenerOptRef, apiListener, ()); }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/main.cc b/test/mocks/server/main.cc index 47f924b5f17a..7faa66127af3 100644 --- a/test/mocks/server/main.cc +++ b/test/mocks/server/main.cc @@ -23,13 +23,10 @@ MockMain::MockMain(int wd_miss, int wd_megamiss, int wd_kill, int wd_multikill) ON_CALL(*this, wdMultiKillTimeout()).WillByDefault(Return(wd_multikill_)); } - MockMain::~MockMain() = default; +} // namespace Configuration +} // namespace Server -} - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/main.h b/test/mocks/server/main.h index 313bdcf1528b..a7b216f10ec7 100644 --- a/test/mocks/server/main.h +++ b/test/mocks/server/main.h @@ -5,8 +5,8 @@ #include #include -#include "envoy/server/overload_manager.h" #include "envoy/server/configuration.h" +#include "envoy/server/overload_manager.h" #include "gmock/gmock.h" @@ -32,8 +32,8 @@ class MockMain : public Main { std::chrono::milliseconds wd_kill_; std::chrono::milliseconds wd_multikill_; }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/mocks.cc b/test/mocks/server/mocks.cc index 87fb1d7c6ddb..3ab8b182b1f7 100644 --- a/test/mocks/server/mocks.cc +++ b/test/mocks/server/mocks.cc @@ -1,2 +1,3 @@ #include "mocks.h" +namespace Envoy {} \ No newline at end of file diff --git a/test/mocks/server/mocks.h b/test/mocks/server/mocks.h index 60c6fdd7afc4..68584ef43819 100644 --- a/test/mocks/server/mocks.h +++ b/test/mocks/server/mocks.h @@ -1,25 +1,27 @@ #pragma once #include "admin.h" +#include "admin_stream.h" +#include "bootstrap_extension_factory.h" #include "config_tracker.h" #include "drain_manager.h" -#include "health_checker_factory_context.h" -#include "listener_factory_context.h" -#include "options.h" -#include "tracer_factory.h" -#include "worker.h" -#include "admin_stream.h" #include "factory_context.h" -#include "hot_restart.h" -#include "listener_manager.h" -#include "overload_manager.h" -#include "transport_socket_factory_context.h" -#include "bootstrap_extension_factory.h" #include "filter_chain_factory_context.h" +#include "guard_dog.h" +#include "health_checker_factory_context.h" +#include "hot_restart.h" #include "instance.h" +#include "listener_component_factory.h" +#include "listener_factory_context.h" +#include "listener_manager.h" #include "main.h" +#include "options.h" +#include "overload_manager.h" #include "server_lifecycle_notifier.h" -#include "watch_dog.h" -#include "guard_dog.h" -#include "listener_component_factory.h" +#include "tracer_factory.h" #include "tracer_factory_context.h" +#include "transport_socket_factory_context.h" +#include "watch_dog.h" +#include "worker.h" #include "worker_factory.h" + +namespace Envoy {} \ No newline at end of file diff --git a/test/mocks/server/options.cc b/test/mocks/server/options.cc index 04e85013e33c..43f3c2ba19c9 100644 --- a/test/mocks/server/options.cc +++ b/test/mocks/server/options.cc @@ -50,8 +50,6 @@ MockOptions::MockOptions(const std::string& config_path) : config_path_(config_p MockOptions::~MockOptions() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/options.h b/test/mocks/server/options.h index 50befaa3b412..c800f2e47e72 100644 --- a/test/mocks/server/options.h +++ b/test/mocks/server/options.h @@ -77,6 +77,6 @@ class MockOptions : public Options { bool cpuset_threads_enabled_{}; std::vector disabled_extensions_; }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/overload_manager.cc b/test/mocks/server/overload_manager.cc index dbe04d629183..264298aca192 100644 --- a/test/mocks/server/overload_manager.cc +++ b/test/mocks/server/overload_manager.cc @@ -2,7 +2,6 @@ #include - #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -21,8 +20,6 @@ MockOverloadManager::MockOverloadManager() { MockOverloadManager::~MockOverloadManager() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/overload_manager.h b/test/mocks/server/overload_manager.h index baf9c55c3ec1..1c4bd036eef6 100644 --- a/test/mocks/server/overload_manager.h +++ b/test/mocks/server/overload_manager.h @@ -25,6 +25,6 @@ class MockOverloadManager : public OverloadManager { ThreadLocalOverloadState overload_state_; }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/server_lifecycle_notifier.cc b/test/mocks/server/server_lifecycle_notifier.cc index 056e6b471dfd..7a1db292035e 100644 --- a/test/mocks/server/server_lifecycle_notifier.cc +++ b/test/mocks/server/server_lifecycle_notifier.cc @@ -18,8 +18,6 @@ MockServerLifecycleNotifier::MockServerLifecycleNotifier() = default; MockServerLifecycleNotifier::~MockServerLifecycleNotifier() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/server_lifecycle_notifier.h b/test/mocks/server/server_lifecycle_notifier.h index 182f63985081..cb93e3302d39 100644 --- a/test/mocks/server/server_lifecycle_notifier.h +++ b/test/mocks/server/server_lifecycle_notifier.h @@ -21,6 +21,6 @@ class MockServerLifecycleNotifier : public ServerLifecycleNotifier { MOCK_METHOD(ServerLifecycleNotifier::HandlePtr, registerCallback, (Stage, StageCallbackWithCompletion)); }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/tracer_factory.cc b/test/mocks/server/tracer_factory.cc index 4a34d9ab2e3e..4380e7d68ebc 100644 --- a/test/mocks/server/tracer_factory.cc +++ b/test/mocks/server/tracer_factory.cc @@ -23,10 +23,8 @@ MockTracerFactory::MockTracerFactory(const std::string& name) : name_(name) { MockTracerFactory::~MockTracerFactory() = default; +} // namespace Configuration +} // namespace Server -} - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/tracer_factory.h b/test/mocks/server/tracer_factory.h index 2814545d2b4e..8f92c1858310 100644 --- a/test/mocks/server/tracer_factory.h +++ b/test/mocks/server/tracer_factory.h @@ -5,8 +5,8 @@ #include #include -#include "envoy/server/tracer_config.h" #include "envoy/protobuf/message_validator.h" +#include "envoy/server/tracer_config.h" #include "gmock/gmock.h" @@ -27,8 +27,8 @@ class MockTracerFactory : public TracerFactory { private: std::string name_; }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/tracer_factory_context.cc b/test/mocks/server/tracer_factory_context.cc index a136c85b03e8..d4072e8c6fa4 100644 --- a/test/mocks/server/tracer_factory_context.cc +++ b/test/mocks/server/tracer_factory_context.cc @@ -21,13 +21,10 @@ MockTracerFactoryContext::MockTracerFactoryContext() { .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); } - MockTracerFactoryContext::~MockTracerFactoryContext() = default; +} // namespace Configuration +} // namespace Server -} - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/tracer_factory_context.h b/test/mocks/server/tracer_factory_context.h index c091fec565fa..94a58deb9d30 100644 --- a/test/mocks/server/tracer_factory_context.h +++ b/test/mocks/server/tracer_factory_context.h @@ -7,11 +7,10 @@ #include "envoy/server/configuration.h" - #include "gmock/gmock.h" - #include "instance.h" #include "tracer_factory.h" + namespace Envoy { namespace Server { namespace Configuration { @@ -25,8 +24,8 @@ class MockTracerFactoryContext : public TracerFactoryContext { testing::NiceMock server_factory_context_; }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/transport_socket_factory_context.cc b/test/mocks/server/transport_socket_factory_context.cc index 6118c4c7ab5a..f15c6595120e 100644 --- a/test/mocks/server/transport_socket_factory_context.cc +++ b/test/mocks/server/transport_socket_factory_context.cc @@ -2,7 +2,6 @@ #include - #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -24,13 +23,10 @@ MockTransportSocketFactoryContext::MockTransportSocketFactoryContext() .WillByDefault(ReturnRef(ProtobufMessage::getStrictValidationVisitor())); } - MockTransportSocketFactoryContext::~MockTransportSocketFactoryContext() = default; +} // namespace Configuration +} // namespace Server -} - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/transport_socket_factory_context.h b/test/mocks/server/transport_socket_factory_context.h index e7b6e458fcc3..0b620229dfb5 100644 --- a/test/mocks/server/transport_socket_factory_context.h +++ b/test/mocks/server/transport_socket_factory_context.h @@ -7,11 +7,11 @@ #include "envoy/server/transport_socket_config.h" -#include "test/mocks/upstream/mocks.h" -#include "test/mocks/api/mocks.h" - #include "common/secret/secret_manager_impl.h" +#include "test/mocks/api/mocks.h" +#include "test/mocks/upstream/mocks.h" + #include "config_tracker.h" #include "gmock/gmock.h" @@ -44,8 +44,8 @@ class MockTransportSocketFactoryContext : public TransportSocketFactoryContext { testing::NiceMock config_tracker_; std::unique_ptr secret_manager_; }; -} +} // namespace Configuration -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/watch_dog.cc b/test/mocks/server/watch_dog.cc index d6b8a7133294..282227c7ba01 100644 --- a/test/mocks/server/watch_dog.cc +++ b/test/mocks/server/watch_dog.cc @@ -18,8 +18,6 @@ MockWatchDog::MockWatchDog() = default; MockWatchDog::~MockWatchDog() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/watch_dog.h b/test/mocks/server/watch_dog.h index 902b2ab6c377..d3bb0d81b29e 100644 --- a/test/mocks/server/watch_dog.h +++ b/test/mocks/server/watch_dog.h @@ -22,6 +22,6 @@ class MockWatchDog : public WatchDog { MOCK_METHOD(Thread::ThreadId, threadId, (), (const)); MOCK_METHOD(MonotonicTime, lastTouchTime, (), (const)); }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/worker.cc b/test/mocks/server/worker.cc index 433898cbc3f1..bf84f990325f 100644 --- a/test/mocks/server/worker.cc +++ b/test/mocks/server/worker.cc @@ -49,8 +49,6 @@ MockWorker::MockWorker() { MockWorker::~MockWorker() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/worker.h b/test/mocks/server/worker.h index 2ef4ad6096a0..558d3ff2b0d1 100644 --- a/test/mocks/server/worker.h +++ b/test/mocks/server/worker.h @@ -55,6 +55,6 @@ class MockWorker : public Worker { std::function remove_listener_completion_; std::function remove_filter_chains_completion_; }; -} +} // namespace Server -} +} // namespace Envoy diff --git a/test/mocks/server/worker_factory.cc b/test/mocks/server/worker_factory.cc index 0f2017c7f12b..d94a37bb8143 100644 --- a/test/mocks/server/worker_factory.cc +++ b/test/mocks/server/worker_factory.cc @@ -18,8 +18,6 @@ MockWorkerFactory::MockWorkerFactory() = default; MockWorkerFactory::~MockWorkerFactory() = default; +} // namespace Server - -} - -} +} // namespace Envoy diff --git a/test/mocks/server/worker_factory.h b/test/mocks/server/worker_factory.h index e31f0fd47deb..9b4845d21328 100644 --- a/test/mocks/server/worker_factory.h +++ b/test/mocks/server/worker_factory.h @@ -8,8 +8,8 @@ #include "envoy/server/worker.h" #include "gmock/gmock.h" - #include "worker.h" + namespace Envoy { namespace Server { class MockWorkerFactory : public WorkerFactory { @@ -24,6 +24,6 @@ class MockWorkerFactory : public WorkerFactory { MOCK_METHOD(Worker*, createWorker_, ()); }; -} +} // namespace Server -} +} // namespace Envoy From f2825fbafad198e4dae53c6999a75af48454f541 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Tue, 30 Jun 2020 01:59:57 +0000 Subject: [PATCH 05/17] move the using into inner namespace and make them fully qualified Signed-off-by: Muge Chen --- test/mocks/server/admin.h | 1 - test/mocks/server/admin_stream.cc | 7 ------- test/mocks/server/config_tracker.h | 1 - test/mocks/server/drain_manager.cc | 11 ++++------- test/mocks/server/factory_context.cc | 14 ++++++-------- .../mocks/server/filter_chain_factory_context.cc | 8 -------- test/mocks/server/guard_dog.cc | 13 +++++-------- .../server/health_checker_factory_context.cc | 10 ++++------ test/mocks/server/hot_restart.cc | 15 ++++++++------- test/mocks/server/instance.cc | 16 ++++++++-------- test/mocks/server/listener_component_factory.cc | 15 ++++++++------- test/mocks/server/listener_factory_context.cc | 8 -------- test/mocks/server/listener_factory_context.h | 2 -- test/mocks/server/listener_manager.cc | 8 +------- test/mocks/server/main.cc | 9 +++------ test/mocks/server/main.h | 2 -- test/mocks/server/options.cc | 15 ++++++++------- test/mocks/server/overload_manager.cc | 9 ++------- test/mocks/server/server_lifecycle_notifier.cc | 8 +------- test/mocks/server/tracer_factory.cc | 16 ++++++++-------- test/mocks/server/tracer_factory_context.cc | 14 ++++++++------ .../server/transport_socket_factory_context.cc | 14 ++++++++------ test/mocks/server/watch_dog.cc | 9 +-------- test/mocks/server/worker.cc | 14 ++++++++------ test/mocks/server/worker_factory.cc | 9 +-------- 25 files changed, 92 insertions(+), 156 deletions(-) diff --git a/test/mocks/server/admin.h b/test/mocks/server/admin.h index 2a82d23859c6..512e3286bfca 100644 --- a/test/mocks/server/admin.h +++ b/test/mocks/server/admin.h @@ -35,5 +35,4 @@ class MockAdmin : public Admin { ::testing::NiceMock config_tracker_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/admin_stream.cc b/test/mocks/server/admin_stream.cc index 8831de7a0245..23e8745aa7e1 100644 --- a/test/mocks/server/admin_stream.cc +++ b/test/mocks/server/admin_stream.cc @@ -5,13 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; - namespace Envoy { namespace Server { MockAdminStream::MockAdminStream() = default; diff --git a/test/mocks/server/config_tracker.h b/test/mocks/server/config_tracker.h index a84b87c7feb0..09f516f0e03c 100644 --- a/test/mocks/server/config_tracker.h +++ b/test/mocks/server/config_tracker.h @@ -26,5 +26,4 @@ class MockConfigTracker : public ConfigTracker { std::unordered_map config_tracker_callbacks_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/drain_manager.cc b/test/mocks/server/drain_manager.cc index 32af0beb7785..de9a53b5afbd 100644 --- a/test/mocks/server/drain_manager.cc +++ b/test/mocks/server/drain_manager.cc @@ -5,15 +5,13 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + +using ::testing::_; +using ::testing::SaveArg; + MockDrainManager::MockDrainManager() { ON_CALL(*this, startDrainSequence(_)).WillByDefault(SaveArg<0>(&drain_sequence_completion_)); } @@ -21,5 +19,4 @@ MockDrainManager::MockDrainManager() { MockDrainManager::~MockDrainManager() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/factory_context.cc b/test/mocks/server/factory_context.cc index 9e86e2faab7a..faa2be43c5e4 100644 --- a/test/mocks/server/factory_context.cc +++ b/test/mocks/server/factory_context.cc @@ -7,16 +7,16 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { namespace Configuration { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnRef; + MockFactoryContext::MockFactoryContext() : singleton_manager_(new Singleton::ManagerImpl(Thread::threadFactoryForTest())), grpc_context_(scope_.symbolTable()), http_context_(scope_.symbolTable()) { @@ -47,7 +47,5 @@ MockFactoryContext::MockFactoryContext() MockFactoryContext::~MockFactoryContext() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/filter_chain_factory_context.cc b/test/mocks/server/filter_chain_factory_context.cc index d2f7e3ed98fd..ed2697d218d4 100644 --- a/test/mocks/server/filter_chain_factory_context.cc +++ b/test/mocks/server/filter_chain_factory_context.cc @@ -5,12 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { @@ -20,7 +14,5 @@ MockFilterChainFactoryContext::MockFilterChainFactoryContext() = default; MockFilterChainFactoryContext::~MockFilterChainFactoryContext() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/guard_dog.cc b/test/mocks/server/guard_dog.cc index 7e72e83ab768..3e131fa363fa 100644 --- a/test/mocks/server/guard_dog.cc +++ b/test/mocks/server/guard_dog.cc @@ -5,16 +5,14 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::NiceMock; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + +using ::testing::_; +using ::testing::NiceMock; +using ::testing::Return; + MockGuardDog::MockGuardDog() : watch_dog_(new NiceMock()) { ON_CALL(*this, createWatchDog(_, _)).WillByDefault(Return(watch_dog_)); } @@ -22,5 +20,4 @@ MockGuardDog::MockGuardDog() : watch_dog_(new NiceMock()) { MockGuardDog::~MockGuardDog() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/health_checker_factory_context.cc b/test/mocks/server/health_checker_factory_context.cc index ce1005ec4daf..2b841fa4c606 100644 --- a/test/mocks/server/health_checker_factory_context.cc +++ b/test/mocks/server/health_checker_factory_context.cc @@ -5,16 +5,14 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { namespace Configuration { + +using ::testing::_; +using ::testing::ReturnRef; + MockHealthCheckerFactoryContext::MockHealthCheckerFactoryContext() { event_logger_ = new testing::NiceMock(); ON_CALL(*this, cluster()).WillByDefault(ReturnRef(cluster_)); diff --git a/test/mocks/server/hot_restart.cc b/test/mocks/server/hot_restart.cc index 07e50121046e..476ca0547c71 100644 --- a/test/mocks/server/hot_restart.cc +++ b/test/mocks/server/hot_restart.cc @@ -5,15 +5,17 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::SaveArg; + MockHotRestart::MockHotRestart() : stats_allocator_(*symbol_table_) { ON_CALL(*this, logLock()).WillByDefault(ReturnRef(log_lock_)); ON_CALL(*this, accessLogLock()).WillByDefault(ReturnRef(access_log_lock_)); @@ -23,5 +25,4 @@ MockHotRestart::MockHotRestart() : stats_allocator_(*symbol_table_) { MockHotRestart::~MockHotRestart() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/instance.cc b/test/mocks/server/instance.cc index b9c9adf38db6..f4ec185e339a 100644 --- a/test/mocks/server/instance.cc +++ b/test/mocks/server/instance.cc @@ -7,15 +7,17 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::SaveArg; + MockInstance::MockInstance() : secret_manager_(std::make_unique(admin_.getConfigTracker())), cluster_manager_(timeSource()), ssl_context_manager_(timeSource()), @@ -82,7 +84,5 @@ MockServerFactoryContext::MockServerFactoryContext() MockServerFactoryContext::~MockServerFactoryContext() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/listener_component_factory.cc b/test/mocks/server/listener_component_factory.cc index e5c42ade62c7..3aa85dbd0426 100644 --- a/test/mocks/server/listener_component_factory.cc +++ b/test/mocks/server/listener_component_factory.cc @@ -8,15 +8,17 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::SaveArg; + MockListenerComponentFactory::MockListenerComponentFactory() : socket_(std::make_shared>()) { ON_CALL(*this, createListenSocket(_, _, _, _)) @@ -34,5 +36,4 @@ MockListenerComponentFactory::MockListenerComponentFactory() MockListenerComponentFactory::~MockListenerComponentFactory() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/listener_factory_context.cc b/test/mocks/server/listener_factory_context.cc index a72e8d830431..0d0fb935db7f 100644 --- a/test/mocks/server/listener_factory_context.cc +++ b/test/mocks/server/listener_factory_context.cc @@ -3,12 +3,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { @@ -18,7 +12,5 @@ MockListenerFactoryContext::MockListenerFactoryContext() = default; MockListenerFactoryContext::~MockListenerFactoryContext() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/listener_factory_context.h b/test/mocks/server/listener_factory_context.h index 1536f1e4b99a..c73732dff393 100644 --- a/test/mocks/server/listener_factory_context.h +++ b/test/mocks/server/listener_factory_context.h @@ -24,7 +24,5 @@ class MockListenerFactoryContext : public MockFactoryContext, public ListenerFac Network::MockListenerConfig listener_config_; }; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/listener_manager.cc b/test/mocks/server/listener_manager.cc index 9fedc2c6825b..cdf86ca6546e 100644 --- a/test/mocks/server/listener_manager.cc +++ b/test/mocks/server/listener_manager.cc @@ -5,19 +5,13 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + MockListenerManager::MockListenerManager() = default; MockListenerManager::~MockListenerManager() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/main.cc b/test/mocks/server/main.cc index 7faa66127af3..b55b0b9e19de 100644 --- a/test/mocks/server/main.cc +++ b/test/mocks/server/main.cc @@ -5,16 +5,13 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { namespace Configuration { + +using ::testing::Return; + MockMain::MockMain(int wd_miss, int wd_megamiss, int wd_kill, int wd_multikill) : wd_miss_(wd_miss), wd_megamiss_(wd_megamiss), wd_kill_(wd_kill), wd_multikill_(wd_multikill) { ON_CALL(*this, wdMissTimeout()).WillByDefault(Return(wd_miss_)); diff --git a/test/mocks/server/main.h b/test/mocks/server/main.h index a7b216f10ec7..573cda3df1f0 100644 --- a/test/mocks/server/main.h +++ b/test/mocks/server/main.h @@ -33,7 +33,5 @@ class MockMain : public Main { std::chrono::milliseconds wd_multikill_; }; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/options.cc b/test/mocks/server/options.cc index 43f3c2ba19c9..edde65515555 100644 --- a/test/mocks/server/options.cc +++ b/test/mocks/server/options.cc @@ -7,15 +7,17 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::SaveArg; + MockOptions::MockOptions(const std::string& config_path) : config_path_(config_path) { ON_CALL(*this, concurrency()).WillByDefault(ReturnPointee(&concurrency_)); ON_CALL(*this, configPath()).WillByDefault(ReturnRef(config_path_)); @@ -51,5 +53,4 @@ MockOptions::MockOptions(const std::string& config_path) : config_path_(config_p MockOptions::~MockOptions() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/overload_manager.cc b/test/mocks/server/overload_manager.cc index 264298aca192..9d623844fdc5 100644 --- a/test/mocks/server/overload_manager.cc +++ b/test/mocks/server/overload_manager.cc @@ -5,15 +5,11 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + +using ::testing::ReturnRef; MockOverloadManager::MockOverloadManager() { ON_CALL(*this, getThreadLocalOverloadState()).WillByDefault(ReturnRef(overload_state_)); } @@ -21,5 +17,4 @@ MockOverloadManager::MockOverloadManager() { MockOverloadManager::~MockOverloadManager() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/server_lifecycle_notifier.cc b/test/mocks/server/server_lifecycle_notifier.cc index 7a1db292035e..a6155908148f 100644 --- a/test/mocks/server/server_lifecycle_notifier.cc +++ b/test/mocks/server/server_lifecycle_notifier.cc @@ -5,19 +5,13 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + MockServerLifecycleNotifier::MockServerLifecycleNotifier() = default; MockServerLifecycleNotifier::~MockServerLifecycleNotifier() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/tracer_factory.cc b/test/mocks/server/tracer_factory.cc index 4380e7d68ebc..5b59f6b2dffa 100644 --- a/test/mocks/server/tracer_factory.cc +++ b/test/mocks/server/tracer_factory.cc @@ -5,16 +5,18 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { namespace Configuration { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::SaveArg; + MockTracerFactory::MockTracerFactory(const std::string& name) : name_(name) { ON_CALL(*this, createEmptyConfigProto()).WillByDefault(Invoke([] { return std::make_unique(); @@ -24,7 +26,5 @@ MockTracerFactory::MockTracerFactory(const std::string& name) : name_(name) { MockTracerFactory::~MockTracerFactory() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/tracer_factory_context.cc b/test/mocks/server/tracer_factory_context.cc index d4072e8c6fa4..d7ada509dd6d 100644 --- a/test/mocks/server/tracer_factory_context.cc +++ b/test/mocks/server/tracer_factory_context.cc @@ -5,16 +5,18 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { namespace Configuration { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::SaveArg; + MockTracerFactoryContext::MockTracerFactoryContext() { ON_CALL(*this, serverFactoryContext()).WillByDefault(ReturnRef(server_factory_context_)); ON_CALL(*this, messageValidationVisitor()) diff --git a/test/mocks/server/transport_socket_factory_context.cc b/test/mocks/server/transport_socket_factory_context.cc index f15c6595120e..67acf000105b 100644 --- a/test/mocks/server/transport_socket_factory_context.cc +++ b/test/mocks/server/transport_socket_factory_context.cc @@ -5,16 +5,18 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { namespace Configuration { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::SaveArg; + MockTransportSocketFactoryContext::MockTransportSocketFactoryContext() : secret_manager_(std::make_unique(config_tracker_)) { ON_CALL(*this, clusterManager()).WillByDefault(ReturnRef(cluster_manager_)); diff --git a/test/mocks/server/watch_dog.cc b/test/mocks/server/watch_dog.cc index 282227c7ba01..f07755963fe6 100644 --- a/test/mocks/server/watch_dog.cc +++ b/test/mocks/server/watch_dog.cc @@ -5,19 +5,12 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; - namespace Envoy { namespace Server { + MockWatchDog::MockWatchDog() = default; MockWatchDog::~MockWatchDog() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/worker.cc b/test/mocks/server/worker.cc index bf84f990325f..fc36bb33b412 100644 --- a/test/mocks/server/worker.cc +++ b/test/mocks/server/worker.cc @@ -5,15 +5,17 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; namespace Envoy { namespace Server { + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::ReturnPointee; +using ::testing::ReturnRef; +using ::testing::SaveArg; + MockWorker::MockWorker() { ON_CALL(*this, addListener(_, _, _)) .WillByDefault( diff --git a/test/mocks/server/worker_factory.cc b/test/mocks/server/worker_factory.cc index d94a37bb8143..6cdaa354eb2c 100644 --- a/test/mocks/server/worker_factory.cc +++ b/test/mocks/server/worker_factory.cc @@ -5,19 +5,12 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using testing::_; -using testing::Invoke; -using testing::Return; -using testing::ReturnPointee; -using testing::ReturnRef; -using testing::SaveArg; - namespace Envoy { namespace Server { + MockWorkerFactory::MockWorkerFactory() = default; MockWorkerFactory::~MockWorkerFactory() = default; } // namespace Server - } // namespace Envoy From 38c5e146f0c8c7a3ce93e686cc977df34e161b34 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Tue, 30 Jun 2020 02:27:46 +0000 Subject: [PATCH 06/17] remove blank lines between closing namespace brackets Signed-off-by: Muge Chen --- test/mocks/server/main.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/mocks/server/main.cc b/test/mocks/server/main.cc index b55b0b9e19de..6b2cc1b28677 100644 --- a/test/mocks/server/main.cc +++ b/test/mocks/server/main.cc @@ -23,7 +23,5 @@ MockMain::MockMain(int wd_miss, int wd_megamiss, int wd_kill, int wd_multikill) MockMain::~MockMain() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy From af2db9dd9acc8363493bf52db8f55e8bb86a1533 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Tue, 30 Jun 2020 02:30:12 +0000 Subject: [PATCH 07/17] remove blank lines between closing namespace bracets Signed-off-by: Muge Chen --- test/mocks/server/admin.cc | 1 - test/mocks/server/admin_stream.cc | 1 - test/mocks/server/admin_stream.h | 1 - test/mocks/server/bootstrap_extension_factory.cc | 2 -- test/mocks/server/bootstrap_extension_factory.h | 2 -- test/mocks/server/drain_manager.h | 1 - test/mocks/server/filter_chain_factory_context.h | 2 -- test/mocks/server/guard_dog.h | 1 - test/mocks/server/health_checker_factory_context.cc | 3 --- test/mocks/server/health_checker_factory_context.h | 1 - test/mocks/server/hot_restart.h | 1 - test/mocks/server/instance.h | 2 -- test/mocks/server/listener_component_factory.h | 1 - test/mocks/server/listener_manager.h | 1 - test/mocks/server/options.h | 1 - test/mocks/server/overload_manager.h | 1 - test/mocks/server/server_lifecycle_notifier.h | 1 - test/mocks/server/tracer_factory.h | 2 -- test/mocks/server/tracer_factory_context.cc | 2 -- test/mocks/server/tracer_factory_context.h | 1 - test/mocks/server/transport_socket_factory_context.cc | 2 -- test/mocks/server/transport_socket_factory_context.h | 2 -- test/mocks/server/watch_dog.h | 1 - test/mocks/server/worker.cc | 1 - test/mocks/server/worker.h | 1 - test/mocks/server/worker_factory.h | 1 - 26 files changed, 36 deletions(-) diff --git a/test/mocks/server/admin.cc b/test/mocks/server/admin.cc index 2411ef375f00..97688fd58154 100644 --- a/test/mocks/server/admin.cc +++ b/test/mocks/server/admin.cc @@ -14,5 +14,4 @@ MockAdmin::MockAdmin() { MockAdmin::~MockAdmin() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/admin_stream.cc b/test/mocks/server/admin_stream.cc index 23e8745aa7e1..9ed778013b18 100644 --- a/test/mocks/server/admin_stream.cc +++ b/test/mocks/server/admin_stream.cc @@ -12,5 +12,4 @@ MockAdminStream::MockAdminStream() = default; MockAdminStream::~MockAdminStream() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/admin_stream.h b/test/mocks/server/admin_stream.h index 1c1900feeaaa..94f722f1df37 100644 --- a/test/mocks/server/admin_stream.h +++ b/test/mocks/server/admin_stream.h @@ -29,5 +29,4 @@ class MockAdminStream : public AdminStream { MOCK_METHOD(Http::Http1StreamEncoderOptionsOptRef, http1StreamEncoderOptions, ()); }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/bootstrap_extension_factory.cc b/test/mocks/server/bootstrap_extension_factory.cc index fa97c07280cd..80984ea4093d 100644 --- a/test/mocks/server/bootstrap_extension_factory.cc +++ b/test/mocks/server/bootstrap_extension_factory.cc @@ -8,7 +8,5 @@ MockBootstrapExtensionFactory::MockBootstrapExtensionFactory() = default; MockBootstrapExtensionFactory::~MockBootstrapExtensionFactory() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/bootstrap_extension_factory.h b/test/mocks/server/bootstrap_extension_factory.h index d38f3c94a981..9bd104ba522c 100644 --- a/test/mocks/server/bootstrap_extension_factory.h +++ b/test/mocks/server/bootstrap_extension_factory.h @@ -23,7 +23,5 @@ class MockBootstrapExtensionFactory : public BootstrapExtensionFactory { MOCK_METHOD(std::string, name, (), (const, override)); }; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/drain_manager.h b/test/mocks/server/drain_manager.h index 278abe2c11b9..dc0331b05876 100644 --- a/test/mocks/server/drain_manager.h +++ b/test/mocks/server/drain_manager.h @@ -25,5 +25,4 @@ class MockDrainManager : public DrainManager { std::function drain_sequence_completion_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/filter_chain_factory_context.h b/test/mocks/server/filter_chain_factory_context.h index 0b2095bd6b17..75dfcdbb0c87 100644 --- a/test/mocks/server/filter_chain_factory_context.h +++ b/test/mocks/server/filter_chain_factory_context.h @@ -18,7 +18,5 @@ class MockFilterChainFactoryContext : public MockFactoryContext, public FilterCh ~MockFilterChainFactoryContext() override; }; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/guard_dog.h b/test/mocks/server/guard_dog.h index 0c5ad2f0e28c..fed29041db3e 100644 --- a/test/mocks/server/guard_dog.h +++ b/test/mocks/server/guard_dog.h @@ -20,5 +20,4 @@ class MockGuardDog : public GuardDog { std::shared_ptr watch_dog_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/health_checker_factory_context.cc b/test/mocks/server/health_checker_factory_context.cc index 2b841fa4c606..54f8dacc429b 100644 --- a/test/mocks/server/health_checker_factory_context.cc +++ b/test/mocks/server/health_checker_factory_context.cc @@ -10,7 +10,6 @@ namespace Envoy { namespace Server { namespace Configuration { -using ::testing::_; using ::testing::ReturnRef; MockHealthCheckerFactoryContext::MockHealthCheckerFactoryContext() { @@ -28,7 +27,5 @@ MockHealthCheckerFactoryContext::MockHealthCheckerFactoryContext() { MockHealthCheckerFactoryContext::~MockHealthCheckerFactoryContext() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/health_checker_factory_context.h b/test/mocks/server/health_checker_factory_context.h index cb1c64eaeac0..3f59ad6c5cf6 100644 --- a/test/mocks/server/health_checker_factory_context.h +++ b/test/mocks/server/health_checker_factory_context.h @@ -45,5 +45,4 @@ class MockHealthCheckerFactoryContext : public virtual HealthCheckerFactoryConte } // namespace Configuration } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/hot_restart.h b/test/mocks/server/hot_restart.h index a73ae73267dd..810c02d07aee 100644 --- a/test/mocks/server/hot_restart.h +++ b/test/mocks/server/hot_restart.h @@ -40,5 +40,4 @@ class MockHotRestart : public HotRestart { Stats::AllocatorImpl stats_allocator_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/instance.h b/test/mocks/server/instance.h index 2ca51ebe348e..314cdcff9efa 100644 --- a/test/mocks/server/instance.h +++ b/test/mocks/server/instance.h @@ -171,7 +171,5 @@ class MockServerFactoryContext : public virtual ServerFactoryContext { Grpc::ContextImpl grpc_context_; }; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/listener_component_factory.h b/test/mocks/server/listener_component_factory.h index d01488999a96..2d3ca8ced6e0 100644 --- a/test/mocks/server/listener_component_factory.h +++ b/test/mocks/server/listener_component_factory.h @@ -49,5 +49,4 @@ class MockListenerComponentFactory : public ListenerComponentFactory { std::shared_ptr socket_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/listener_manager.h b/test/mocks/server/listener_manager.h index c1b68d0ea33b..7c530c42ccc1 100644 --- a/test/mocks/server/listener_manager.h +++ b/test/mocks/server/listener_manager.h @@ -31,5 +31,4 @@ class MockListenerManager : public ListenerManager { MOCK_METHOD(ApiListenerOptRef, apiListener, ()); }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/options.h b/test/mocks/server/options.h index c800f2e47e72..4c92d4634f2f 100644 --- a/test/mocks/server/options.h +++ b/test/mocks/server/options.h @@ -78,5 +78,4 @@ class MockOptions : public Options { std::vector disabled_extensions_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/overload_manager.h b/test/mocks/server/overload_manager.h index 1c4bd036eef6..a4a8f6ca82e9 100644 --- a/test/mocks/server/overload_manager.h +++ b/test/mocks/server/overload_manager.h @@ -26,5 +26,4 @@ class MockOverloadManager : public OverloadManager { ThreadLocalOverloadState overload_state_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/server_lifecycle_notifier.h b/test/mocks/server/server_lifecycle_notifier.h index cb93e3302d39..3a1a514aac26 100644 --- a/test/mocks/server/server_lifecycle_notifier.h +++ b/test/mocks/server/server_lifecycle_notifier.h @@ -22,5 +22,4 @@ class MockServerLifecycleNotifier : public ServerLifecycleNotifier { (Stage, StageCallbackWithCompletion)); }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/tracer_factory.h b/test/mocks/server/tracer_factory.h index 8f92c1858310..5e01f9621384 100644 --- a/test/mocks/server/tracer_factory.h +++ b/test/mocks/server/tracer_factory.h @@ -28,7 +28,5 @@ class MockTracerFactory : public TracerFactory { std::string name_; }; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/tracer_factory_context.cc b/test/mocks/server/tracer_factory_context.cc index d7ada509dd6d..8bedded4d59a 100644 --- a/test/mocks/server/tracer_factory_context.cc +++ b/test/mocks/server/tracer_factory_context.cc @@ -26,7 +26,5 @@ MockTracerFactoryContext::MockTracerFactoryContext() { MockTracerFactoryContext::~MockTracerFactoryContext() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/tracer_factory_context.h b/test/mocks/server/tracer_factory_context.h index 94a58deb9d30..a8d7dfae029a 100644 --- a/test/mocks/server/tracer_factory_context.h +++ b/test/mocks/server/tracer_factory_context.h @@ -27,5 +27,4 @@ class MockTracerFactoryContext : public TracerFactoryContext { } // namespace Configuration } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/transport_socket_factory_context.cc b/test/mocks/server/transport_socket_factory_context.cc index 67acf000105b..ecb9dac8f8a2 100644 --- a/test/mocks/server/transport_socket_factory_context.cc +++ b/test/mocks/server/transport_socket_factory_context.cc @@ -28,7 +28,5 @@ MockTransportSocketFactoryContext::MockTransportSocketFactoryContext() MockTransportSocketFactoryContext::~MockTransportSocketFactoryContext() = default; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/transport_socket_factory_context.h b/test/mocks/server/transport_socket_factory_context.h index 0b620229dfb5..932d06d9e980 100644 --- a/test/mocks/server/transport_socket_factory_context.h +++ b/test/mocks/server/transport_socket_factory_context.h @@ -45,7 +45,5 @@ class MockTransportSocketFactoryContext : public TransportSocketFactoryContext { std::unique_ptr secret_manager_; }; } // namespace Configuration - } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/watch_dog.h b/test/mocks/server/watch_dog.h index d3bb0d81b29e..4060fc309e96 100644 --- a/test/mocks/server/watch_dog.h +++ b/test/mocks/server/watch_dog.h @@ -23,5 +23,4 @@ class MockWatchDog : public WatchDog { MOCK_METHOD(MonotonicTime, lastTouchTime, (), (const)); }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/worker.cc b/test/mocks/server/worker.cc index fc36bb33b412..d5c6fec58728 100644 --- a/test/mocks/server/worker.cc +++ b/test/mocks/server/worker.cc @@ -52,5 +52,4 @@ MockWorker::MockWorker() { MockWorker::~MockWorker() = default; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/worker.h b/test/mocks/server/worker.h index 558d3ff2b0d1..7cc68ead9990 100644 --- a/test/mocks/server/worker.h +++ b/test/mocks/server/worker.h @@ -56,5 +56,4 @@ class MockWorker : public Worker { std::function remove_filter_chains_completion_; }; } // namespace Server - } // namespace Envoy diff --git a/test/mocks/server/worker_factory.h b/test/mocks/server/worker_factory.h index 9b4845d21328..06486cc9b95d 100644 --- a/test/mocks/server/worker_factory.h +++ b/test/mocks/server/worker_factory.h @@ -25,5 +25,4 @@ class MockWorkerFactory : public WorkerFactory { MOCK_METHOD(Worker*, createWorker_, ()); }; } // namespace Server - } // namespace Envoy From f98507ebf27e776c77a98cbbde7499e83470b7c3 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Tue, 30 Jun 2020 19:35:34 +0000 Subject: [PATCH 08/17] remove unused std libs Signed-off-by: Muge Chen --- test/mocks/server/BUILD | 2 +- test/mocks/server/admin.cc | 2 -- test/mocks/server/admin_stream.h | 7 ------- test/mocks/server/bootstrap_extension_factory.h | 5 ----- test/mocks/server/factory_context.h | 8 -------- test/mocks/server/filter_chain_factory_context.h | 5 ----- test/mocks/server/guard_dog.cc | 2 -- test/mocks/server/health_checker_factory_context.h | 5 ----- test/mocks/server/hot_restart.h | 5 ----- test/mocks/server/instance.cc | 2 -- test/mocks/server/instance.h | 5 ----- test/mocks/server/listener_component_factory.cc | 3 --- test/mocks/server/listener_component_factory.h | 5 ----- test/mocks/server/listener_factory_context.h | 5 ----- test/mocks/server/listener_manager.h | 5 ----- test/mocks/server/main.cc | 2 -- test/mocks/server/mocks.cc | 3 --- test/mocks/server/mocks.h | 4 +--- test/mocks/server/options.cc | 2 -- test/mocks/server/options.h | 5 ----- test/mocks/server/overload_manager.h | 3 --- test/mocks/server/server_lifecycle_notifier.h | 5 ----- test/mocks/server/tracer_factory.h | 5 ----- test/mocks/server/tracer_factory_context.h | 5 ----- test/mocks/server/transport_socket_factory_context.h | 5 ----- test/mocks/server/watch_dog.h | 5 ----- test/mocks/server/worker.h | 5 ----- test/mocks/server/worker_factory.cc | 2 -- test/mocks/server/worker_factory.h | 5 ----- 29 files changed, 2 insertions(+), 120 deletions(-) delete mode 100644 test/mocks/server/mocks.cc diff --git a/test/mocks/server/BUILD b/test/mocks/server/BUILD index bc7bdb02448d..b6f0d0b35ad0 100644 --- a/test/mocks/server/BUILD +++ b/test/mocks/server/BUILD @@ -284,7 +284,7 @@ envoy_cc_mock( envoy_cc_mock( name = "server_mocks", - srcs = ["mocks.cc"], + srcs = [], hdrs = ["mocks.h"], deps = [ "//test/mocks/server:admin_mocks", diff --git a/test/mocks/server/admin.cc b/test/mocks/server/admin.cc index 97688fd58154..435c14f6e973 100644 --- a/test/mocks/server/admin.cc +++ b/test/mocks/server/admin.cc @@ -1,7 +1,5 @@ #include "admin.h" -#include - #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/test/mocks/server/admin_stream.h b/test/mocks/server/admin_stream.h index 94f722f1df37..d7972b4ae27c 100644 --- a/test/mocks/server/admin_stream.h +++ b/test/mocks/server/admin_stream.h @@ -1,17 +1,10 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/admin.h" #include "test/mocks/http/mocks.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" -#include "spdlog/spdlog.h" namespace Envoy { namespace Server { diff --git a/test/mocks/server/bootstrap_extension_factory.h b/test/mocks/server/bootstrap_extension_factory.h index 9bd104ba522c..f6421f788788 100644 --- a/test/mocks/server/bootstrap_extension_factory.h +++ b/test/mocks/server/bootstrap_extension_factory.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/bootstrap_extension_config.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/factory_context.h b/test/mocks/server/factory_context.h index 89e50fdcdc07..cd1c70d4ecd6 100644 --- a/test/mocks/server/factory_context.h +++ b/test/mocks/server/factory_context.h @@ -1,23 +1,15 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/configuration.h" #include "extensions/transport_sockets/tls/context_manager_impl.h" -#include "absl/strings/string_view.h" #include "admin.h" -#include "config_tracker.h" #include "drain_manager.h" #include "gmock/gmock.h" #include "instance.h" #include "overload_manager.h" #include "server_lifecycle_notifier.h" -#include "spdlog/spdlog.h" namespace Envoy { namespace Server { diff --git a/test/mocks/server/filter_chain_factory_context.h b/test/mocks/server/filter_chain_factory_context.h index 75dfcdbb0c87..f09e7a565722 100644 --- a/test/mocks/server/filter_chain_factory_context.h +++ b/test/mocks/server/filter_chain_factory_context.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/filter_config.h" #include "factory_context.h" diff --git a/test/mocks/server/guard_dog.cc b/test/mocks/server/guard_dog.cc index 3e131fa363fa..7ec29fd922d6 100644 --- a/test/mocks/server/guard_dog.cc +++ b/test/mocks/server/guard_dog.cc @@ -1,7 +1,5 @@ #include "guard_dog.h" -#include - #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/test/mocks/server/health_checker_factory_context.h b/test/mocks/server/health_checker_factory_context.h index 3f59ad6c5cf6..1d49abffb481 100644 --- a/test/mocks/server/health_checker_factory_context.h +++ b/test/mocks/server/health_checker_factory_context.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/health_checker_config.h" #include "test/mocks/api/mocks.h" diff --git a/test/mocks/server/hot_restart.h b/test/mocks/server/hot_restart.h index 810c02d07aee..c6edd13d8905 100644 --- a/test/mocks/server/hot_restart.h +++ b/test/mocks/server/hot_restart.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/instance.h" #include "test/mocks/stats/mocks.h" diff --git a/test/mocks/server/instance.cc b/test/mocks/server/instance.cc index f4ec185e339a..f65f7cad8783 100644 --- a/test/mocks/server/instance.cc +++ b/test/mocks/server/instance.cc @@ -1,7 +1,5 @@ #include "instance.h" -#include - #include "common/singleton/manager_impl.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/instance.h b/test/mocks/server/instance.h index 314cdcff9efa..67da77794772 100644 --- a/test/mocks/server/instance.h +++ b/test/mocks/server/instance.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/instance.h" #include "common/grpc/context_impl.h" diff --git a/test/mocks/server/listener_component_factory.cc b/test/mocks/server/listener_component_factory.cc index 3aa85dbd0426..905ee8a068f9 100644 --- a/test/mocks/server/listener_component_factory.cc +++ b/test/mocks/server/listener_component_factory.cc @@ -1,8 +1,5 @@ #include "listener_component_factory.h" -#include - -#include "envoy/admin/v3/server_info.pb.h" #include "envoy/config/core/v3/base.pb.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/listener_component_factory.h b/test/mocks/server/listener_component_factory.h index 2d3ca8ced6e0..84d73dd4bfd5 100644 --- a/test/mocks/server/listener_component_factory.h +++ b/test/mocks/server/listener_component_factory.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/config/listener/v3/listener_components.pb.h" #include "envoy/server/drain_manager.h" #include "envoy/server/listener_manager.h" diff --git a/test/mocks/server/listener_factory_context.h b/test/mocks/server/listener_factory_context.h index c73732dff393..8d322735b577 100644 --- a/test/mocks/server/listener_factory_context.h +++ b/test/mocks/server/listener_factory_context.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/listener_manager.h" #include "factory_context.h" diff --git a/test/mocks/server/listener_manager.h b/test/mocks/server/listener_manager.h index 7c530c42ccc1..889dfa1f521f 100644 --- a/test/mocks/server/listener_manager.h +++ b/test/mocks/server/listener_manager.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/listener_manager.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/main.cc b/test/mocks/server/main.cc index 6b2cc1b28677..62385e04aafa 100644 --- a/test/mocks/server/main.cc +++ b/test/mocks/server/main.cc @@ -1,7 +1,5 @@ #include "main.h" -#include - #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/test/mocks/server/mocks.cc b/test/mocks/server/mocks.cc deleted file mode 100644 index 3ab8b182b1f7..000000000000 --- a/test/mocks/server/mocks.cc +++ /dev/null @@ -1,3 +0,0 @@ -#include "mocks.h" - -namespace Envoy {} \ No newline at end of file diff --git a/test/mocks/server/mocks.h b/test/mocks/server/mocks.h index 68584ef43819..c312d7f27e6e 100644 --- a/test/mocks/server/mocks.h +++ b/test/mocks/server/mocks.h @@ -22,6 +22,4 @@ #include "transport_socket_factory_context.h" #include "watch_dog.h" #include "worker.h" -#include "worker_factory.h" - -namespace Envoy {} \ No newline at end of file +#include "worker_factory.h" \ No newline at end of file diff --git a/test/mocks/server/options.cc b/test/mocks/server/options.cc index edde65515555..ae7ebb8b268b 100644 --- a/test/mocks/server/options.cc +++ b/test/mocks/server/options.cc @@ -1,7 +1,5 @@ #include "options.h" -#include - #include "envoy/admin/v3/server_info.pb.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/options.h b/test/mocks/server/options.h index 4c92d4634f2f..31a6112dca35 100644 --- a/test/mocks/server/options.h +++ b/test/mocks/server/options.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/config/bootstrap/v3/bootstrap.pb.h" #include "envoy/server/options.h" diff --git a/test/mocks/server/overload_manager.h b/test/mocks/server/overload_manager.h index a4a8f6ca82e9..8ce63cef1b12 100644 --- a/test/mocks/server/overload_manager.h +++ b/test/mocks/server/overload_manager.h @@ -1,8 +1,5 @@ #pragma once -#include -#include -#include #include #include "envoy/server/overload_manager.h" diff --git a/test/mocks/server/server_lifecycle_notifier.h b/test/mocks/server/server_lifecycle_notifier.h index 3a1a514aac26..3442a194ac32 100644 --- a/test/mocks/server/server_lifecycle_notifier.h +++ b/test/mocks/server/server_lifecycle_notifier.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/lifecycle_notifier.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/tracer_factory.h b/test/mocks/server/tracer_factory.h index 5e01f9621384..e342116ee2d5 100644 --- a/test/mocks/server/tracer_factory.h +++ b/test/mocks/server/tracer_factory.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/protobuf/message_validator.h" #include "envoy/server/tracer_config.h" diff --git a/test/mocks/server/tracer_factory_context.h b/test/mocks/server/tracer_factory_context.h index a8d7dfae029a..66a0212d0bb7 100644 --- a/test/mocks/server/tracer_factory_context.h +++ b/test/mocks/server/tracer_factory_context.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/configuration.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/transport_socket_factory_context.h b/test/mocks/server/transport_socket_factory_context.h index 932d06d9e980..a86f2b348485 100644 --- a/test/mocks/server/transport_socket_factory_context.h +++ b/test/mocks/server/transport_socket_factory_context.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/transport_socket_config.h" #include "common/secret/secret_manager_impl.h" diff --git a/test/mocks/server/watch_dog.h b/test/mocks/server/watch_dog.h index 4060fc309e96..105761781c36 100644 --- a/test/mocks/server/watch_dog.h +++ b/test/mocks/server/watch_dog.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/watchdog.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/worker.h b/test/mocks/server/worker.h index 7cc68ead9990..978ab3bbcc21 100644 --- a/test/mocks/server/worker.h +++ b/test/mocks/server/worker.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/worker.h" #include "absl/strings/string_view.h" diff --git a/test/mocks/server/worker_factory.cc b/test/mocks/server/worker_factory.cc index 6cdaa354eb2c..65844ae8cc21 100644 --- a/test/mocks/server/worker_factory.cc +++ b/test/mocks/server/worker_factory.cc @@ -1,7 +1,5 @@ #include "worker_factory.h" -#include - #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/test/mocks/server/worker_factory.h b/test/mocks/server/worker_factory.h index 06486cc9b95d..3c05ed76566c 100644 --- a/test/mocks/server/worker_factory.h +++ b/test/mocks/server/worker_factory.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - #include "envoy/server/worker.h" #include "gmock/gmock.h" From 93dadb56b8be570261cfd437dba437e108575613 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Tue, 30 Jun 2020 20:58:46 +0000 Subject: [PATCH 09/17] run the formatter and add no lint to mocks.h Signed-off-by: Muge Chen --- test/mocks/server/BUILD | 1 - test/mocks/server/drain_manager.cc | 1 - test/mocks/server/factory_context.cc | 1 - test/mocks/server/filter_chain_factory_context.cc | 1 - test/mocks/server/guard_dog.cc | 1 - test/mocks/server/health_checker_factory_context.cc | 1 - test/mocks/server/hot_restart.cc | 1 - test/mocks/server/instance.cc | 1 - test/mocks/server/listener_component_factory.cc | 1 - test/mocks/server/listener_factory_context.cc | 1 - test/mocks/server/listener_manager.cc | 1 - test/mocks/server/main.cc | 1 - test/mocks/server/mocks.h | 5 ++++- test/mocks/server/options.cc | 1 - test/mocks/server/overload_manager.cc | 1 - test/mocks/server/server_lifecycle_notifier.cc | 1 - test/mocks/server/tracer_factory.cc | 1 - test/mocks/server/tracer_factory_context.cc | 1 - test/mocks/server/transport_socket_factory_context.cc | 1 - test/mocks/server/worker.cc | 1 - 20 files changed, 4 insertions(+), 20 deletions(-) diff --git a/test/mocks/server/BUILD b/test/mocks/server/BUILD index b6f0d0b35ad0..35a1ac14b80a 100644 --- a/test/mocks/server/BUILD +++ b/test/mocks/server/BUILD @@ -103,7 +103,6 @@ envoy_cc_mock( "//include/envoy/server:drain_manager_interface", "//include/envoy/server:listener_manager_interface", "//test/mocks/network:network_mocks", - "@envoy_api//envoy/admin/v3:pkg_cc_proto", "@envoy_api//envoy/config/core/v3:pkg_cc_proto", "@envoy_api//envoy/config/listener/v3:pkg_cc_proto", ], diff --git a/test/mocks/server/drain_manager.cc b/test/mocks/server/drain_manager.cc index de9a53b5afbd..15735d57834c 100644 --- a/test/mocks/server/drain_manager.cc +++ b/test/mocks/server/drain_manager.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/factory_context.cc b/test/mocks/server/factory_context.cc index faa2be43c5e4..dfe546912e6f 100644 --- a/test/mocks/server/factory_context.cc +++ b/test/mocks/server/factory_context.cc @@ -7,7 +7,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { namespace Configuration { diff --git a/test/mocks/server/filter_chain_factory_context.cc b/test/mocks/server/filter_chain_factory_context.cc index ed2697d218d4..674f95f4a558 100644 --- a/test/mocks/server/filter_chain_factory_context.cc +++ b/test/mocks/server/filter_chain_factory_context.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { namespace Configuration { diff --git a/test/mocks/server/guard_dog.cc b/test/mocks/server/guard_dog.cc index 7ec29fd922d6..e5e552c234f5 100644 --- a/test/mocks/server/guard_dog.cc +++ b/test/mocks/server/guard_dog.cc @@ -3,7 +3,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/health_checker_factory_context.cc b/test/mocks/server/health_checker_factory_context.cc index 54f8dacc429b..f6a17d962e2a 100644 --- a/test/mocks/server/health_checker_factory_context.cc +++ b/test/mocks/server/health_checker_factory_context.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { namespace Configuration { diff --git a/test/mocks/server/hot_restart.cc b/test/mocks/server/hot_restart.cc index 476ca0547c71..d54ff1d646a1 100644 --- a/test/mocks/server/hot_restart.cc +++ b/test/mocks/server/hot_restart.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/instance.cc b/test/mocks/server/instance.cc index f65f7cad8783..1c4f44d5f7c9 100644 --- a/test/mocks/server/instance.cc +++ b/test/mocks/server/instance.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/listener_component_factory.cc b/test/mocks/server/listener_component_factory.cc index 905ee8a068f9..fbab73d60fb8 100644 --- a/test/mocks/server/listener_component_factory.cc +++ b/test/mocks/server/listener_component_factory.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/listener_factory_context.cc b/test/mocks/server/listener_factory_context.cc index 0d0fb935db7f..99a7678c1a27 100644 --- a/test/mocks/server/listener_factory_context.cc +++ b/test/mocks/server/listener_factory_context.cc @@ -3,7 +3,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { namespace Configuration { diff --git a/test/mocks/server/listener_manager.cc b/test/mocks/server/listener_manager.cc index cdf86ca6546e..0448ff4e7122 100644 --- a/test/mocks/server/listener_manager.cc +++ b/test/mocks/server/listener_manager.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/main.cc b/test/mocks/server/main.cc index 62385e04aafa..2cc3e8dfeec4 100644 --- a/test/mocks/server/main.cc +++ b/test/mocks/server/main.cc @@ -3,7 +3,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { namespace Configuration { diff --git a/test/mocks/server/mocks.h b/test/mocks/server/mocks.h index c312d7f27e6e..d041412d01d1 100644 --- a/test/mocks/server/mocks.h +++ b/test/mocks/server/mocks.h @@ -1,4 +1,7 @@ #pragma once + +// NOLINT(namespace-envoy) + #include "admin.h" #include "admin_stream.h" #include "bootstrap_extension_factory.h" @@ -22,4 +25,4 @@ #include "transport_socket_factory_context.h" #include "watch_dog.h" #include "worker.h" -#include "worker_factory.h" \ No newline at end of file +#include "worker_factory.h" diff --git a/test/mocks/server/options.cc b/test/mocks/server/options.cc index ae7ebb8b268b..6cc02ed3d2dd 100644 --- a/test/mocks/server/options.cc +++ b/test/mocks/server/options.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/overload_manager.cc b/test/mocks/server/overload_manager.cc index 9d623844fdc5..d105df80e690 100644 --- a/test/mocks/server/overload_manager.cc +++ b/test/mocks/server/overload_manager.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/server_lifecycle_notifier.cc b/test/mocks/server/server_lifecycle_notifier.cc index a6155908148f..1cd6cd9d3b5c 100644 --- a/test/mocks/server/server_lifecycle_notifier.cc +++ b/test/mocks/server/server_lifecycle_notifier.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { diff --git a/test/mocks/server/tracer_factory.cc b/test/mocks/server/tracer_factory.cc index 5b59f6b2dffa..e7eb8b99138d 100644 --- a/test/mocks/server/tracer_factory.cc +++ b/test/mocks/server/tracer_factory.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { namespace Configuration { diff --git a/test/mocks/server/tracer_factory_context.cc b/test/mocks/server/tracer_factory_context.cc index 8bedded4d59a..b7cbbae8a532 100644 --- a/test/mocks/server/tracer_factory_context.cc +++ b/test/mocks/server/tracer_factory_context.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { namespace Configuration { diff --git a/test/mocks/server/transport_socket_factory_context.cc b/test/mocks/server/transport_socket_factory_context.cc index ecb9dac8f8a2..fddf89ebc374 100644 --- a/test/mocks/server/transport_socket_factory_context.cc +++ b/test/mocks/server/transport_socket_factory_context.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { namespace Configuration { diff --git a/test/mocks/server/worker.cc b/test/mocks/server/worker.cc index d5c6fec58728..abd11a046b33 100644 --- a/test/mocks/server/worker.cc +++ b/test/mocks/server/worker.cc @@ -5,7 +5,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" - namespace Envoy { namespace Server { From a7cea475fbba01d7fae98463ffd1da26b636603e Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Wed, 1 Jul 2020 02:58:31 +0000 Subject: [PATCH 10/17] merge upstream test file to pass ci Signed-off-by: Muge Chen --- test/integration/cx_limit_integration_test.cc | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 test/integration/cx_limit_integration_test.cc diff --git a/test/integration/cx_limit_integration_test.cc b/test/integration/cx_limit_integration_test.cc new file mode 100644 index 000000000000..6ffb4952ae63 --- /dev/null +++ b/test/integration/cx_limit_integration_test.cc @@ -0,0 +1,148 @@ +#include "envoy/config/bootstrap/v3/bootstrap.pb.h" +#include "envoy/network/filter.h" +#include "envoy/registry/registry.h" + +#include "common/network/utility.h" + +#include "test/config/utility.h" +#include "test/integration/integration.h" +#include "test/test_common/logging.h" +#include "test/test_common/simulated_time_system.h" + +#include "gtest/gtest.h" + +namespace Envoy { +namespace { + +class ConnectionLimitIntegrationTest : public testing::TestWithParam, + public Event::TestUsingSimulatedTime, + public BaseIntegrationTest { +public: + ConnectionLimitIntegrationTest() + : BaseIntegrationTest(GetParam(), ConfigHelper::tcpProxyConfig()) {} + + void setEmptyListenerLimit() { + config_helper_.addRuntimeOverride("envoy.resource_limits.listener.listener_0.connection_limit", + ""); + } + + void setListenerLimit(const uint32_t num_conns) { + config_helper_.addRuntimeOverride("envoy.resource_limits.listener.listener_0.connection_limit", + std::to_string(num_conns)); + } + + void setGlobalLimit(std::string&& num_conns) { + config_helper_.addRuntimeOverride("overload.global_downstream_max_connections", num_conns); + } + + void initialize() override { BaseIntegrationTest::initialize(); } + + // Assumes a limit of 2 connections. + void doTest(std::function init_func, std::string&& check_stat) { + init_func(); + + std::vector tcp_clients; + std::vector raw_conns; + + tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); + raw_conns.emplace_back(); + ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back())); + ASSERT_TRUE(tcp_clients.back()->connected()); + + tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); + raw_conns.emplace_back(); + ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back())); + ASSERT_TRUE(tcp_clients.back()->connected()); + + tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); + raw_conns.emplace_back(); + ASSERT_FALSE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back())); + tcp_clients.back()->waitForDisconnect(); + + // Get rid of the client that failed to connect. + tcp_clients.back()->close(); + tcp_clients.pop_back(); + + // Close the first connection that was successful so that we can open a new successful + // connection. + tcp_clients.front()->close(); + ASSERT_TRUE(raw_conns.front()->close()); + ASSERT_TRUE(raw_conns.front()->waitForDisconnect()); + + tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); + raw_conns.emplace_back(); + ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back())); + ASSERT_TRUE(tcp_clients.back()->connected()); + + const bool isV4 = (version_ == Network::Address::IpVersion::v4); + auto local_address = isV4 ? Network::Utility::getCanonicalIpv4LoopbackAddress() + : Network::Utility::getIpv6LoopbackAddress(); + + const std::string counter_prefix = (isV4 ? "listener.127.0.0.1_0." : "listener.[__1]_0."); + + test_server_->waitForCounterEq(counter_prefix + check_stat, 1); + + for (auto& tcp_client : tcp_clients) { + tcp_client->close(); + } + + tcp_clients.clear(); + raw_conns.clear(); + } +}; + +INSTANTIATE_TEST_SUITE_P(IpVersions, ConnectionLimitIntegrationTest, + testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), + TestUtility::ipTestParamsToString); + +TEST_P(ConnectionLimitIntegrationTest, TestListenerLimit) { + std::function init_func = [this]() { + setListenerLimit(2); + initialize(); + }; + + doTest(init_func, "downstream_cx_overflow"); +} + +TEST_P(ConnectionLimitIntegrationTest, TestEmptyGlobalCxRuntimeLimit) { + const std::string log_line = "no configured limit to the number of allowed active connections."; + EXPECT_LOG_CONTAINS("warn", log_line, { initialize(); }); +} + +TEST_P(ConnectionLimitIntegrationTest, TestEmptyListenerRuntimeLimit) { + const std::string log_line = + "Listener connection limit runtime key " + "envoy.resource_limits.listener.listener_0.connection_limit is empty. There are currently " + "no limitations on the number of accepted connections for listener listener_0."; + EXPECT_LOG_CONTAINS("warn", log_line, { + setEmptyListenerLimit(); + initialize(); + }); +} + +TEST_P(ConnectionLimitIntegrationTest, TestGlobalLimit) { + std::function init_func = [this]() { + // Includes twice the number of connections expected because the tracking is performed via a + // static variable and the fake upstream has a listener. This causes upstream connections to the + // fake upstream to also be tracked as part of the global downstream connection tracking. + setGlobalLimit("4"); + initialize(); + }; + + doTest(init_func, "downstream_global_cx_overflow"); +} + +TEST_P(ConnectionLimitIntegrationTest, TestBothLimits) { + std::function init_func = [this]() { + // Setting the listener limit to a much higher value and making sure the right stat gets + // incremented when both limits are set. + setGlobalLimit("4"); + setListenerLimit(100); + initialize(); + }; + + doTest(init_func, "downstream_global_cx_overflow"); +} + +} // namespace +} // namespace Envoy From a1668a30287337d6b883c1e544356c5f7dfefcda Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Wed, 1 Jul 2020 03:03:56 +0000 Subject: [PATCH 11/17] merge upstream changes to pass ci Signed-off-by: Muge Chen --- test/integration/BUILD | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/integration/BUILD b/test/integration/BUILD index 1922ef9f1e89..388bb393d405 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -1304,6 +1304,21 @@ envoy_cc_test( ], ) +envoy_cc_test( + name = "cx_limit_integration_test", + srcs = ["cx_limit_integration_test.cc"], + deps = [ + ":http_integration_lib", + "//include/envoy/network:filter_interface", + "//include/envoy/registry", + "//source/extensions/filters/network/tcp_proxy:config", + "//test/config:utility_lib", + "//test/test_common:logging_lib", + "//test/test_common:simulated_time_system_lib", + "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto", + ], +) + envoy_cc_test( name = "local_reply_integration_test", srcs = [ From 3807f54135c9b015781ccb5615d6ba4c12866fb0 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 6 Jul 2020 00:01:15 -0400 Subject: [PATCH 12/17] remove unused using statement Signed-off-by: Muge Chen --- test/mocks/server/hot_restart.cc | 5 ----- test/mocks/server/instance.cc | 4 ---- test/mocks/server/listener_component_factory.cc | 4 ---- test/mocks/server/options.cc | 2 -- test/mocks/server/tracer_factory.cc | 5 ----- test/mocks/server/tracer_factory_context.cc | 5 ----- test/mocks/server/transport_socket_factory_context.cc | 5 ----- test/mocks/server/worker.cc | 4 ---- 8 files changed, 34 deletions(-) diff --git a/test/mocks/server/hot_restart.cc b/test/mocks/server/hot_restart.cc index d54ff1d646a1..8a11dbe8011d 100644 --- a/test/mocks/server/hot_restart.cc +++ b/test/mocks/server/hot_restart.cc @@ -8,12 +8,7 @@ namespace Envoy { namespace Server { -using ::testing::_; -using ::testing::Invoke; -using ::testing::Return; -using ::testing::ReturnPointee; using ::testing::ReturnRef; -using ::testing::SaveArg; MockHotRestart::MockHotRestart() : stats_allocator_(*symbol_table_) { ON_CALL(*this, logLock()).WillByDefault(ReturnRef(log_lock_)); diff --git a/test/mocks/server/instance.cc b/test/mocks/server/instance.cc index 1c4f44d5f7c9..91c102c45267 100644 --- a/test/mocks/server/instance.cc +++ b/test/mocks/server/instance.cc @@ -8,12 +8,8 @@ namespace Envoy { namespace Server { -using ::testing::_; -using ::testing::Invoke; using ::testing::Return; -using ::testing::ReturnPointee; using ::testing::ReturnRef; -using ::testing::SaveArg; MockInstance::MockInstance() : secret_manager_(std::make_unique(admin_.getConfigTracker())), diff --git a/test/mocks/server/listener_component_factory.cc b/test/mocks/server/listener_component_factory.cc index fbab73d60fb8..a0b00b7bc756 100644 --- a/test/mocks/server/listener_component_factory.cc +++ b/test/mocks/server/listener_component_factory.cc @@ -10,10 +10,6 @@ namespace Server { using ::testing::_; using ::testing::Invoke; -using ::testing::Return; -using ::testing::ReturnPointee; -using ::testing::ReturnRef; -using ::testing::SaveArg; MockListenerComponentFactory::MockListenerComponentFactory() : socket_(std::make_shared>()) { diff --git a/test/mocks/server/options.cc b/test/mocks/server/options.cc index 6cc02ed3d2dd..c407ab6ef907 100644 --- a/test/mocks/server/options.cc +++ b/test/mocks/server/options.cc @@ -8,12 +8,10 @@ namespace Envoy { namespace Server { -using ::testing::_; using ::testing::Invoke; using ::testing::Return; using ::testing::ReturnPointee; using ::testing::ReturnRef; -using ::testing::SaveArg; MockOptions::MockOptions(const std::string& config_path) : config_path_(config_path) { ON_CALL(*this, concurrency()).WillByDefault(ReturnPointee(&concurrency_)); diff --git a/test/mocks/server/tracer_factory.cc b/test/mocks/server/tracer_factory.cc index e7eb8b99138d..7dcaa39f7ae1 100644 --- a/test/mocks/server/tracer_factory.cc +++ b/test/mocks/server/tracer_factory.cc @@ -9,12 +9,7 @@ namespace Envoy { namespace Server { namespace Configuration { -using ::testing::_; using ::testing::Invoke; -using ::testing::Return; -using ::testing::ReturnPointee; -using ::testing::ReturnRef; -using ::testing::SaveArg; MockTracerFactory::MockTracerFactory(const std::string& name) : name_(name) { ON_CALL(*this, createEmptyConfigProto()).WillByDefault(Invoke([] { diff --git a/test/mocks/server/tracer_factory_context.cc b/test/mocks/server/tracer_factory_context.cc index b7cbbae8a532..992a3854179f 100644 --- a/test/mocks/server/tracer_factory_context.cc +++ b/test/mocks/server/tracer_factory_context.cc @@ -9,12 +9,7 @@ namespace Envoy { namespace Server { namespace Configuration { -using ::testing::_; -using ::testing::Invoke; -using ::testing::Return; -using ::testing::ReturnPointee; using ::testing::ReturnRef; -using ::testing::SaveArg; MockTracerFactoryContext::MockTracerFactoryContext() { ON_CALL(*this, serverFactoryContext()).WillByDefault(ReturnRef(server_factory_context_)); diff --git a/test/mocks/server/transport_socket_factory_context.cc b/test/mocks/server/transport_socket_factory_context.cc index fddf89ebc374..0e4e50231a7d 100644 --- a/test/mocks/server/transport_socket_factory_context.cc +++ b/test/mocks/server/transport_socket_factory_context.cc @@ -9,12 +9,7 @@ namespace Envoy { namespace Server { namespace Configuration { -using ::testing::_; -using ::testing::Invoke; -using ::testing::Return; -using ::testing::ReturnPointee; using ::testing::ReturnRef; -using ::testing::SaveArg; MockTransportSocketFactoryContext::MockTransportSocketFactoryContext() : secret_manager_(std::make_unique(config_tracker_)) { diff --git a/test/mocks/server/worker.cc b/test/mocks/server/worker.cc index abd11a046b33..a7e981b299b1 100644 --- a/test/mocks/server/worker.cc +++ b/test/mocks/server/worker.cc @@ -10,10 +10,6 @@ namespace Server { using ::testing::_; using ::testing::Invoke; -using ::testing::Return; -using ::testing::ReturnPointee; -using ::testing::ReturnRef; -using ::testing::SaveArg; MockWorker::MockWorker() { ON_CALL(*this, addListener(_, _, _)) From 517ab026281deffd0f35ad6d423493fa080ca19a Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 6 Jul 2020 04:07:40 +0000 Subject: [PATCH 13/17] resolve conflicts Signed-off-by: Muge Chen --- test/integration/BUILD | 3 +++ test/integration/cx_limit_integration_test.cc | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/integration/BUILD b/test/integration/BUILD index 388bb393d405..fe34c7575262 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -594,6 +594,7 @@ envoy_cc_test_library( "//source/common/buffer:buffer_lib", "//source/common/buffer:zero_copy_input_stream_lib", "//source/common/common:assert_lib", + "//source/common/common:basic_resource_lib", "//source/common/common:minimal_logger_lib", "//source/common/config:api_version_lib", "//source/common/config:version_converter_lib", @@ -1307,6 +1308,8 @@ envoy_cc_test( envoy_cc_test( name = "cx_limit_integration_test", srcs = ["cx_limit_integration_test.cc"], + # TODO(11841) See if this can be reenabled once the test is deflaked. + tags = ["fails_on_windows"], deps = [ ":http_integration_lib", "//include/envoy/network:filter_interface", diff --git a/test/integration/cx_limit_integration_test.cc b/test/integration/cx_limit_integration_test.cc index 6ffb4952ae63..abdc5711fe2e 100644 --- a/test/integration/cx_limit_integration_test.cc +++ b/test/integration/cx_limit_integration_test.cc @@ -43,7 +43,6 @@ class ConnectionLimitIntegrationTest : public testing::TestWithParam tcp_clients; std::vector raw_conns; - tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); raw_conns.emplace_back(); ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back())); @@ -56,7 +55,8 @@ class ConnectionLimitIntegrationTest : public testing::TestWithParamwaitForRawConnection(raw_conns.back())); + ASSERT_FALSE( + fake_upstreams_[0]->waitForRawConnection(raw_conns.back(), std::chrono::milliseconds(500))); tcp_clients.back()->waitForDisconnect(); // Get rid of the client that failed to connect. @@ -66,7 +66,6 @@ class ConnectionLimitIntegrationTest : public testing::TestWithParamclose(); - ASSERT_TRUE(raw_conns.front()->close()); ASSERT_TRUE(raw_conns.front()->waitForDisconnect()); tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); From 13084f4ef7fe6ece61639806d3f7f2f960471832 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 6 Jul 2020 04:10:04 +0000 Subject: [PATCH 14/17] resolve changes Signed-off-by: Muge Chen --- test/integration/BUILD | 17 -- test/integration/cx_limit_integration_test.cc | 147 ------------------ 2 files changed, 164 deletions(-) delete mode 100644 test/integration/cx_limit_integration_test.cc diff --git a/test/integration/BUILD b/test/integration/BUILD index fe34c7575262..4008f8681eca 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -1305,23 +1305,6 @@ envoy_cc_test( ], ) -envoy_cc_test( - name = "cx_limit_integration_test", - srcs = ["cx_limit_integration_test.cc"], - # TODO(11841) See if this can be reenabled once the test is deflaked. - tags = ["fails_on_windows"], - deps = [ - ":http_integration_lib", - "//include/envoy/network:filter_interface", - "//include/envoy/registry", - "//source/extensions/filters/network/tcp_proxy:config", - "//test/config:utility_lib", - "//test/test_common:logging_lib", - "//test/test_common:simulated_time_system_lib", - "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto", - ], -) - envoy_cc_test( name = "local_reply_integration_test", srcs = [ diff --git a/test/integration/cx_limit_integration_test.cc b/test/integration/cx_limit_integration_test.cc deleted file mode 100644 index abdc5711fe2e..000000000000 --- a/test/integration/cx_limit_integration_test.cc +++ /dev/null @@ -1,147 +0,0 @@ -#include "envoy/config/bootstrap/v3/bootstrap.pb.h" -#include "envoy/network/filter.h" -#include "envoy/registry/registry.h" - -#include "common/network/utility.h" - -#include "test/config/utility.h" -#include "test/integration/integration.h" -#include "test/test_common/logging.h" -#include "test/test_common/simulated_time_system.h" - -#include "gtest/gtest.h" - -namespace Envoy { -namespace { - -class ConnectionLimitIntegrationTest : public testing::TestWithParam, - public Event::TestUsingSimulatedTime, - public BaseIntegrationTest { -public: - ConnectionLimitIntegrationTest() - : BaseIntegrationTest(GetParam(), ConfigHelper::tcpProxyConfig()) {} - - void setEmptyListenerLimit() { - config_helper_.addRuntimeOverride("envoy.resource_limits.listener.listener_0.connection_limit", - ""); - } - - void setListenerLimit(const uint32_t num_conns) { - config_helper_.addRuntimeOverride("envoy.resource_limits.listener.listener_0.connection_limit", - std::to_string(num_conns)); - } - - void setGlobalLimit(std::string&& num_conns) { - config_helper_.addRuntimeOverride("overload.global_downstream_max_connections", num_conns); - } - - void initialize() override { BaseIntegrationTest::initialize(); } - - // Assumes a limit of 2 connections. - void doTest(std::function init_func, std::string&& check_stat) { - init_func(); - - std::vector tcp_clients; - std::vector raw_conns; - tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); - raw_conns.emplace_back(); - ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back())); - ASSERT_TRUE(tcp_clients.back()->connected()); - - tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); - raw_conns.emplace_back(); - ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back())); - ASSERT_TRUE(tcp_clients.back()->connected()); - - tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); - raw_conns.emplace_back(); - ASSERT_FALSE( - fake_upstreams_[0]->waitForRawConnection(raw_conns.back(), std::chrono::milliseconds(500))); - tcp_clients.back()->waitForDisconnect(); - - // Get rid of the client that failed to connect. - tcp_clients.back()->close(); - tcp_clients.pop_back(); - - // Close the first connection that was successful so that we can open a new successful - // connection. - tcp_clients.front()->close(); - ASSERT_TRUE(raw_conns.front()->waitForDisconnect()); - - tcp_clients.emplace_back(makeTcpConnection(lookupPort("listener_0"))); - raw_conns.emplace_back(); - ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(raw_conns.back())); - ASSERT_TRUE(tcp_clients.back()->connected()); - - const bool isV4 = (version_ == Network::Address::IpVersion::v4); - auto local_address = isV4 ? Network::Utility::getCanonicalIpv4LoopbackAddress() - : Network::Utility::getIpv6LoopbackAddress(); - - const std::string counter_prefix = (isV4 ? "listener.127.0.0.1_0." : "listener.[__1]_0."); - - test_server_->waitForCounterEq(counter_prefix + check_stat, 1); - - for (auto& tcp_client : tcp_clients) { - tcp_client->close(); - } - - tcp_clients.clear(); - raw_conns.clear(); - } -}; - -INSTANTIATE_TEST_SUITE_P(IpVersions, ConnectionLimitIntegrationTest, - testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), - TestUtility::ipTestParamsToString); - -TEST_P(ConnectionLimitIntegrationTest, TestListenerLimit) { - std::function init_func = [this]() { - setListenerLimit(2); - initialize(); - }; - - doTest(init_func, "downstream_cx_overflow"); -} - -TEST_P(ConnectionLimitIntegrationTest, TestEmptyGlobalCxRuntimeLimit) { - const std::string log_line = "no configured limit to the number of allowed active connections."; - EXPECT_LOG_CONTAINS("warn", log_line, { initialize(); }); -} - -TEST_P(ConnectionLimitIntegrationTest, TestEmptyListenerRuntimeLimit) { - const std::string log_line = - "Listener connection limit runtime key " - "envoy.resource_limits.listener.listener_0.connection_limit is empty. There are currently " - "no limitations on the number of accepted connections for listener listener_0."; - EXPECT_LOG_CONTAINS("warn", log_line, { - setEmptyListenerLimit(); - initialize(); - }); -} - -TEST_P(ConnectionLimitIntegrationTest, TestGlobalLimit) { - std::function init_func = [this]() { - // Includes twice the number of connections expected because the tracking is performed via a - // static variable and the fake upstream has a listener. This causes upstream connections to the - // fake upstream to also be tracked as part of the global downstream connection tracking. - setGlobalLimit("4"); - initialize(); - }; - - doTest(init_func, "downstream_global_cx_overflow"); -} - -TEST_P(ConnectionLimitIntegrationTest, TestBothLimits) { - std::function init_func = [this]() { - // Setting the listener limit to a much higher value and making sure the right stat gets - // incremented when both limits are set. - setGlobalLimit("4"); - setListenerLimit(100); - initialize(); - }; - - doTest(init_func, "downstream_global_cx_overflow"); -} - -} // namespace -} // namespace Envoy From f07736f803d6723dbe9acf6e15088b0294f53641 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 6 Jul 2020 04:11:39 +0000 Subject: [PATCH 15/17] resolve conflicts Signed-off-by: Muge Chen --- test/integration/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/BUILD b/test/integration/BUILD index 4008f8681eca..1922ef9f1e89 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -594,7 +594,6 @@ envoy_cc_test_library( "//source/common/buffer:buffer_lib", "//source/common/buffer:zero_copy_input_stream_lib", "//source/common/common:assert_lib", - "//source/common/common:basic_resource_lib", "//source/common/common:minimal_logger_lib", "//source/common/config:api_version_lib", "//source/common/config:version_converter_lib", From e1e8acab154170cd87367dee86effadfe029de67 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 6 Jul 2020 05:25:19 +0000 Subject: [PATCH 16/17] remove unused using statements Signed-off-by: Muge Chen --- test/mocks/server/factory_context.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/mocks/server/factory_context.cc b/test/mocks/server/factory_context.cc index dfe546912e6f..974371a1d3b5 100644 --- a/test/mocks/server/factory_context.cc +++ b/test/mocks/server/factory_context.cc @@ -11,9 +11,6 @@ namespace Envoy { namespace Server { namespace Configuration { -using ::testing::_; -using ::testing::Invoke; -using ::testing::Return; using ::testing::ReturnRef; MockFactoryContext::MockFactoryContext() From df9a803766590df2498c95a3c69c1f021abf0cc3 Mon Sep 17 00:00:00 2001 From: Muge Chen Date: Mon, 6 Jul 2020 14:12:43 +0000 Subject: [PATCH 17/17] Kick CI Signed-off-by: Muge Chen