diff --git a/include/envoy/runtime/runtime.h b/include/envoy/runtime/runtime.h index b3e3ebeb468a3..bd3e759ee175e 100644 --- a/include/envoy/runtime/runtime.h +++ b/include/envoy/runtime/runtime.h @@ -220,11 +220,11 @@ class Loader { virtual void initialize(Upstream::ClusterManager& cm) PURE; /** - * @return Snapshot& the current snapshot. This reference is safe to use for the duration of + * @return const Snapshot& the current snapshot. This reference is safe to use for the duration of * the calling routine, but may be overwritten on a future event loop cycle so should be * fetched again when needed. */ - virtual Snapshot& snapshot() PURE; + virtual const Snapshot& snapshot() PURE; /** * Merge the given map of key-value pairs into the runtime's state. To remove a previous merge for diff --git a/source/common/runtime/runtime_impl.cc b/source/common/runtime/runtime_impl.cc index a1369e6ab141d..ae565aecbde34 100644 --- a/source/common/runtime/runtime_impl.cc +++ b/source/common/runtime/runtime_impl.cc @@ -557,7 +557,7 @@ void LoaderImpl::loadNewSnapshot() { }); } -Snapshot& LoaderImpl::snapshot() { return tls_->getTyped(); } +const Snapshot& LoaderImpl::snapshot() { return tls_->getTyped(); } void LoaderImpl::mergeValues(const std::unordered_map& values) { if (admin_layer_ == nullptr) { diff --git a/source/common/runtime/runtime_impl.h b/source/common/runtime/runtime_impl.h index 855dc1ea370e1..b9344d0cc9724 100644 --- a/source/common/runtime/runtime_impl.h +++ b/source/common/runtime/runtime_impl.h @@ -243,7 +243,7 @@ class LoaderImpl : public Loader, Logger::Loggable { // Runtime::Loader void initialize(Upstream::ClusterManager& cm) override; - Snapshot& snapshot() override; + const Snapshot& snapshot() override; void mergeValues(const std::unordered_map& values) override; private: diff --git a/test/common/runtime/runtime_impl_test.cc b/test/common/runtime/runtime_impl_test.cc index cb73ae6e73bf3..e5edecfc5b88b 100644 --- a/test/common/runtime/runtime_impl_test.cc +++ b/test/common/runtime/runtime_impl_test.cc @@ -155,7 +155,7 @@ TEST_F(DiskLoaderImplTest, All) { EXPECT_EQ(123UL, loader_->snapshot().getInteger("file4", 1)); bool value; - SnapshotImpl* snapshot = reinterpret_cast(&loader_->snapshot()); + const SnapshotImpl* snapshot = reinterpret_cast(&loader_->snapshot()); // Validate that the layer name is set properly for static layers. EXPECT_EQ("base", snapshot->getLayers()[0]->name()); @@ -538,7 +538,7 @@ TEST_F(StaticLoaderImplTest, ProtoParsing) { // Boolean getting. bool value; - SnapshotImpl* snapshot = reinterpret_cast(&loader_->snapshot()); + const SnapshotImpl* snapshot = reinterpret_cast(&loader_->snapshot()); EXPECT_EQ(true, snapshot->getBoolean("file11", value)); EXPECT_EQ(true, value); diff --git a/test/mocks/runtime/mocks.h b/test/mocks/runtime/mocks.h index 3592a40200fae..6e4385b4a76a9 100644 --- a/test/mocks/runtime/mocks.h +++ b/test/mocks/runtime/mocks.h @@ -63,7 +63,7 @@ class MockLoader : public Loader { ~MockLoader() override; MOCK_METHOD1(initialize, void(Upstream::ClusterManager& cm)); - MOCK_METHOD0(snapshot, Snapshot&()); + MOCK_METHOD0(snapshot, const Snapshot&()); MOCK_METHOD1(mergeValues, void(const std::unordered_map&)); testing::NiceMock snapshot_;