Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/test/mocks/upstream/cluster_manager.cc
Line
Count
Source (jump to first uncovered line)
1
#include "cluster_manager.h"
2
3
#include <chrono>
4
#include <functional>
5
6
#include "gmock/gmock.h"
7
#include "gtest/gtest.h"
8
9
namespace Envoy {
10
namespace Upstream {
11
12
using ::testing::Return;
13
using ::testing::ReturnRef;
14
15
0
MockClusterManager::MockClusterManager(TimeSource&) : MockClusterManager() {}
16
17
MockClusterManager::MockClusterManager()
18
    : cluster_stat_names_(*symbol_table_), cluster_config_update_stat_names_(*symbol_table_),
19
      cluster_lb_stat_names_(*symbol_table_), cluster_endpoint_stat_names_(*symbol_table_),
20
      cluster_load_report_stat_names_(*symbol_table_),
21
      cluster_circuit_breakers_stat_names_(*symbol_table_),
22
      cluster_request_response_size_stat_names_(*symbol_table_),
23
27.9k
      cluster_timeout_budget_stat_names_(*symbol_table_) {
24
27.9k
  ON_CALL(*this, bindConfig()).WillByDefault(ReturnRef(bind_config_));
25
27.9k
  ON_CALL(*this, adsMux()).WillByDefault(Return(ads_mux_));
26
27.9k
  ON_CALL(*this, grpcAsyncClientManager()).WillByDefault(ReturnRef(async_client_manager_));
27
27.9k
  ON_CALL(*this, localClusterName()).WillByDefault((ReturnRef(local_cluster_name_)));
28
27.9k
  ON_CALL(*this, subscriptionFactory()).WillByDefault(ReturnRef(subscription_factory_));
29
27.9k
  ON_CALL(*this, allocateOdCdsApi(_, _, _))
30
27.9k
      .WillByDefault(Invoke([](const envoy::config::core::v3::ConfigSource&,
31
27.9k
                               OptRef<xds::core::v3::ResourceLocator>,
32
27.9k
                               ProtobufMessage::ValidationVisitor&) -> OdCdsApiHandlePtr {
33
0
        return MockOdCdsApiHandle::create();
34
0
      }));
35
27.9k
}
36
37
27.9k
MockClusterManager::~MockClusterManager() = default;
38
39
void MockClusterManager::initializeClusters(const std::vector<std::string>& active_cluster_names,
40
0
                                            const std::vector<std::string>&) {
41
0
  active_clusters_.clear();
42
0
  ClusterManager::ClusterInfoMaps info_map;
43
0
  for (const auto& name : active_cluster_names) {
44
0
    auto new_cluster = std::make_unique<NiceMock<MockCluster>>();
45
0
    new_cluster->info_->name_ = name;
46
0
    info_map.active_clusters_.emplace(name, *new_cluster);
47
0
    active_clusters_.emplace(name, std::move(new_cluster));
48
0
  }
49
50
  // TODO(mattklein123): Add support for warming clusters when needed.
51
52
0
  ON_CALL(*this, clusters()).WillByDefault(Return(info_map));
53
0
}
54
55
void MockClusterManager::initializeThreadLocalClusters(
56
1
    const std::vector<std::string>& cluster_names) {
57
  // TODO(mattklein123): This should create a dedicated and new mock for each initialized cluster,
58
  // but this has larger test implications. I will fix this in a follow up.
59
1
  for (const auto& cluster_name : cluster_names) {
60
1
    ON_CALL(*this, getThreadLocalCluster(absl::string_view(cluster_name)))
61
1
        .WillByDefault(Return(&thread_local_cluster_));
62
1
  }
63
1
}
64
65
0
envoy::config::core::v3::BindConfig& MockClusterManager::mutableBindConfig() {
66
0
  if (!bind_config_.has_value()) {
67
0
    bind_config_ = envoy::config::core::v3::BindConfig{};
68
0
  }
69
0
  return *bind_config_;
70
0
}
71
72
} // namespace Upstream
73
} // namespace Envoy