#include "cluster_manager.h" #include #include #include "gmock/gmock.h" #include "gtest/gtest.h" namespace Envoy { namespace Upstream { using ::testing::_; using ::testing::Eq; using ::testing::Return; using ::testing::ReturnRef; MockClusterManager::MockClusterManager(TimeSource&) : MockClusterManager() {} MockClusterManager::MockClusterManager() { ON_CALL(*this, httpConnPoolForCluster(_, _, _, _)).WillByDefault(Return(&conn_pool_)); ON_CALL(*this, tcpConnPoolForCluster(_, _, _)).WillByDefault(Return(&tcp_conn_pool_)); ON_CALL(*this, httpAsyncClientForCluster(_)).WillByDefault(ReturnRef(async_client_)); ON_CALL(*this, httpAsyncClientForCluster(_)).WillByDefault((ReturnRef(async_client_))); ON_CALL(*this, bindConfig()).WillByDefault(ReturnRef(bind_config_)); ON_CALL(*this, adsMux()).WillByDefault(Return(ads_mux_)); ON_CALL(*this, grpcAsyncClientManager()).WillByDefault(ReturnRef(async_client_manager_)); ON_CALL(*this, localClusterName()).WillByDefault((ReturnRef(local_cluster_name_))); ON_CALL(*this, subscriptionFactory()).WillByDefault(ReturnRef(subscription_factory_)); } MockClusterManager::~MockClusterManager() = default; void MockClusterManager::initializeClusters(const std::vector& active_cluster_names, const std::vector&) { active_clusters_.clear(); ClusterManager::ClusterInfoMaps info_map; for (const auto& name : active_cluster_names) { auto new_cluster = std::make_unique>(); new_cluster->info_->name_ = name; info_map.active_clusters_.emplace(name, *new_cluster); active_clusters_.emplace(name, std::move(new_cluster)); } // TODO(mattklein123): Add support for warming clusters when needed. ON_CALL(*this, clusters()).WillByDefault(Return(info_map)); } void MockClusterManager::initializeThreadLocalClusters( const std::vector& cluster_names) { // TODO(mattklein123): This should create a dedicated and new mock for each initialized cluster, // but this has larger test implications. I will fix this in a follow up. for (const auto& cluster_name : cluster_names) { ON_CALL(*this, getThreadLocalCluster(cluster_name)) .WillByDefault(Return(&thread_local_cluster_)); } } } // namespace Upstream } // namespace Envoy