/proc/self/cwd/test/mocks/local_info/mocks.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "mocks.h" |
2 | | |
3 | | #include "source/common/network/address_impl.h" |
4 | | |
5 | | #include "gmock/gmock.h" |
6 | | #include "gtest/gtest.h" |
7 | | |
8 | | using testing::Const; |
9 | | using testing::Return; |
10 | | using testing::ReturnRef; |
11 | | |
12 | | namespace Envoy { |
13 | | namespace LocalInfo { |
14 | | |
15 | 68.1k | MockLocalInfo::MockLocalInfo() : address_(new Network::Address::Ipv4Instance("127.0.0.1")) { |
16 | 68.1k | node_.set_id("node_name"); |
17 | 68.1k | node_.set_cluster("cluster_name"); |
18 | 68.1k | node_.mutable_locality()->set_zone("zone_name"); |
19 | 68.1k | ON_CALL(*this, address()).WillByDefault(Return(address_)); |
20 | 68.1k | ON_CALL(*this, zoneName()).WillByDefault(ReturnRef(node_.locality().zone())); |
21 | 68.1k | ON_CALL(*this, zoneStatName()).WillByDefault(ReturnRef(makeZoneStatName())); |
22 | 68.1k | ON_CALL(*this, clusterName()).WillByDefault(ReturnRef(node_.cluster())); |
23 | 68.1k | ON_CALL(*this, nodeName()).WillByDefault(ReturnRef(node_.id())); |
24 | 68.1k | ON_CALL(*this, node()).WillByDefault(ReturnRef(node_)); |
25 | 68.1k | ON_CALL(*this, contextProvider()).WillByDefault(ReturnRef(context_provider_)); |
26 | 68.1k | ON_CALL(Const(*this), contextProvider()).WillByDefault(ReturnRef(context_provider_)); |
27 | 68.1k | } |
28 | | |
29 | 68.1k | MockLocalInfo::~MockLocalInfo() = default; |
30 | | |
31 | 68.1k | const Stats::StatName& MockLocalInfo::makeZoneStatName() const { |
32 | 68.1k | if (zone_stat_name_storage_ == nullptr || |
33 | 68.1k | symbol_table_->toString(zone_stat_name_) != node_.locality().zone()) { |
34 | 68.1k | zone_stat_name_storage_ = |
35 | 68.1k | std::make_unique<Stats::StatNameManagedStorage>(node_.locality().zone(), *symbol_table_); |
36 | 68.1k | zone_stat_name_ = zone_stat_name_storage_->statName(); |
37 | 68.1k | } |
38 | 68.1k | return zone_stat_name_; |
39 | 68.1k | } |
40 | | |
41 | | } // namespace LocalInfo |
42 | | } // namespace Envoy |