/proc/self/cwd/test/mocks/stats/mocks.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "mocks.h" |
2 | | |
3 | | #include <memory> |
4 | | |
5 | | #include "source/common/stats/symbol_table.h" |
6 | | |
7 | | #include "gmock/gmock.h" |
8 | | #include "gtest/gtest.h" |
9 | | |
10 | | using testing::_; |
11 | | using testing::Invoke; |
12 | | using testing::NiceMock; |
13 | | using testing::Return; |
14 | | using testing::ReturnPointee; |
15 | | using testing::ReturnRef; |
16 | | |
17 | | namespace Envoy { |
18 | | namespace Stats { |
19 | | |
20 | 434k | MockCounter::MockCounter() { |
21 | 434k | ON_CALL(*this, used()).WillByDefault(ReturnPointee(&used_)); |
22 | 434k | ON_CALL(*this, hidden()).WillByDefault(ReturnPointee(&hidden_)); |
23 | 434k | ON_CALL(*this, value()).WillByDefault(ReturnPointee(&value_)); |
24 | 434k | ON_CALL(*this, latch()).WillByDefault(ReturnPointee(&latch_)); |
25 | 434k | } |
26 | 434k | MockCounter::~MockCounter() = default; |
27 | | |
28 | 434k | MockGauge::MockGauge() : used_(false), value_(0), import_mode_(ImportMode::Accumulate) { |
29 | 434k | ON_CALL(*this, used()).WillByDefault(ReturnPointee(&used_)); |
30 | 434k | ON_CALL(*this, hidden()).WillByDefault(ReturnPointee(&hidden_)); |
31 | 434k | ON_CALL(*this, value()).WillByDefault(ReturnPointee(&value_)); |
32 | 434k | ON_CALL(*this, importMode()).WillByDefault(ReturnPointee(&import_mode_)); |
33 | 434k | } |
34 | 434k | MockGauge::~MockGauge() = default; |
35 | | |
36 | 0 | MockTextReadout::MockTextReadout() { |
37 | 0 | ON_CALL(*this, used()).WillByDefault(ReturnPointee(&used_)); |
38 | 0 | ON_CALL(*this, hidden()).WillByDefault(ReturnPointee(&hidden_)); |
39 | 0 | ON_CALL(*this, value()).WillByDefault(ReturnPointee(&value_)); |
40 | 0 | } |
41 | 0 | MockTextReadout::~MockTextReadout() = default; |
42 | | |
43 | 1 | MockHistogram::MockHistogram() { |
44 | 1 | ON_CALL(*this, unit()).WillByDefault(ReturnPointee(&unit_)); |
45 | 1 | ON_CALL(*this, recordValue(_)).WillByDefault(Invoke([this](uint64_t value) { |
46 | 0 | if (store_ != nullptr) { |
47 | 0 | store_->deliverHistogramToSinks(*this, value); |
48 | 0 | } |
49 | 0 | })); |
50 | 1 | } |
51 | 1 | MockHistogram::~MockHistogram() = default; |
52 | | |
53 | 0 | MockParentHistogram::MockParentHistogram() { |
54 | 0 | ON_CALL(*this, used()).WillByDefault(ReturnPointee(&used_)); |
55 | 0 | ON_CALL(*this, hidden()).WillByDefault(ReturnPointee(&hidden_)); |
56 | 0 | ON_CALL(*this, unit()).WillByDefault(ReturnPointee(&unit_)); |
57 | 0 | ON_CALL(*this, recordValue(_)).WillByDefault(Invoke([this](uint64_t value) { |
58 | 0 | if (store_ != nullptr) { |
59 | 0 | store_->deliverHistogramToSinks(*this, value); |
60 | 0 | } |
61 | 0 | })); |
62 | 0 | ON_CALL(*this, intervalStatistics()).WillByDefault(ReturnRef(*histogram_stats_)); |
63 | 0 | ON_CALL(*this, cumulativeStatistics()).WillByDefault(ReturnRef(*histogram_stats_)); |
64 | 0 | } |
65 | 0 | MockParentHistogram::~MockParentHistogram() = default; |
66 | | |
67 | 0 | MockMetricSnapshot::MockMetricSnapshot() { |
68 | 0 | ON_CALL(*this, counters()).WillByDefault(ReturnRef(counters_)); |
69 | 0 | ON_CALL(*this, gauges()).WillByDefault(ReturnRef(gauges_)); |
70 | 0 | ON_CALL(*this, histograms()).WillByDefault(ReturnRef(histograms_)); |
71 | 0 | ON_CALL(*this, hostCounters()).WillByDefault(ReturnRef(host_counters_)); |
72 | 0 | ON_CALL(*this, hostGauges()).WillByDefault(ReturnRef(host_gauges_)); |
73 | 0 | ON_CALL(*this, snapshotTime()).WillByDefault(Return(snapshot_time_)); |
74 | 0 | } |
75 | | |
76 | 0 | MockMetricSnapshot::~MockMetricSnapshot() = default; |
77 | | |
78 | 0 | MockSink::MockSink() = default; |
79 | 0 | MockSink::~MockSink() = default; |
80 | | |
81 | 0 | MockSinkPredicates::MockSinkPredicates() = default; |
82 | 0 | MockSinkPredicates::~MockSinkPredicates() = default; |
83 | | |
84 | | MockScope::MockScope(StatName prefix, MockStore& store) |
85 | 434k | : TestUtil::TestScope(prefix, store), mock_store_(store) {} |
86 | | |
87 | | Counter& MockScope::counterFromStatNameWithTags(const StatName& name, |
88 | 0 | StatNameTagVectorOptConstRef) { |
89 | | // We always just respond with the mocked counter, so the tags don't matter. |
90 | 0 | return mock_store_.counter(symbolTable().toString(name)); |
91 | 0 | } |
92 | | Gauge& MockScope::gaugeFromStatNameWithTags(const StatName& name, StatNameTagVectorOptConstRef, |
93 | 0 | Gauge::ImportMode import_mode) { |
94 | | // We always just respond with the mocked gauge, so the tags don't matter. |
95 | 0 | return mock_store_.gauge(symbolTable().toString(name), import_mode); |
96 | 0 | } |
97 | | Histogram& MockScope::histogramFromStatNameWithTags(const StatName& name, |
98 | | StatNameTagVectorOptConstRef, |
99 | 0 | Histogram::Unit unit) { |
100 | 0 | return mock_store_.histogram(symbolTable().toString(name), unit); |
101 | 0 | } |
102 | | TextReadout& MockScope::textReadoutFromStatNameWithTags(const StatName& name, |
103 | 0 | StatNameTagVectorOptConstRef) { |
104 | | // We always just respond with the mocked counter, so the tags don't matter. |
105 | 0 | return mock_store_.textReadout(symbolTable().toString(name)); |
106 | 0 | } |
107 | | |
108 | 434k | MockStore::MockStore() { |
109 | 434k | ON_CALL(*this, counter(_)).WillByDefault(ReturnRef(counter_)); |
110 | 434k | ON_CALL(*this, gauge(_, _)).WillByDefault(ReturnRef(gauge_)); |
111 | 434k | ON_CALL(*this, histogram(_, _)) |
112 | 434k | .WillByDefault(Invoke([this](const std::string& name, Histogram::Unit unit) -> Histogram& { |
113 | 0 | auto* histogram = new NiceMock<MockHistogram>(); // symbol_table_); |
114 | 0 | histogram->name_ = name; |
115 | 0 | histogram->unit_ = unit; |
116 | 0 | histogram->store_ = this; |
117 | 0 | histograms_.emplace_back(histogram); |
118 | 0 | return *histogram; |
119 | 0 | })); |
120 | 434k | } |
121 | 434k | MockStore::~MockStore() = default; |
122 | | |
123 | 434k | ScopeSharedPtr MockStore::makeScope(StatName prefix) { |
124 | 434k | return std::make_shared<MockScope>(prefix, *this); |
125 | 434k | } |
126 | | |
127 | 1.73M | MockIsolatedStatsStore::MockIsolatedStatsStore() = default; |
128 | 1.73M | MockIsolatedStatsStore::~MockIsolatedStatsStore() = default; |
129 | | |
130 | 0 | MockStatsMatcher::MockStatsMatcher() = default; |
131 | 0 | MockStatsMatcher::~MockStatsMatcher() = default; |
132 | | |
133 | | } // namespace Stats |
134 | | } // namespace Envoy |