userver: dynamic_config::StorageMock Class Reference
No Matches
dynamic_config::StorageMock Class Referencefinal

#include <userver/dynamic_config/storage_mock.hpp>

Detailed Description

Backing storage for dynamic_config::Source in tests and benchmarks.

Make sure that StorageMock outlives all the acquired pointers!
class DummyClient;
std::string DummyFunction(const dynamic_config::Snapshot& config) {
return config[kDummyConfig].bar;
UTEST(DynamicConfig, Snippet) {
// The 'StorageMock' will only contain the specified configs, and nothing more
{kDummyConfig, {42, "what"}},
{kIntConfig, 5},
EXPECT_EQ(DummyFunction(storage.GetSnapshot()), "what");
// 'DummyClient' stores 'dynamic_config::Source' for access to latest configs
DummyClient client{storage.GetSource()};
storage.Extend({{kDummyConfig, {-10000, "invalid"}}});
UEXPECT_THROW(client.DoStuff(), std::runtime_error);
const auto kJson = formats::json::FromString(R"( {"foo": 42, "bar": "what"} )");
UTEST(DynamicConfig, FromJson) {
{kDummyConfig, kJson},
{kIntConfig, 5},
const auto config = storage.GetSnapshot();
EXPECT_EQ(config[kDummyConfig].foo, 42);
EXPECT_EQ(config[kDummyConfig].bar, "what");
EXPECT_EQ(config[kIntConfig], 5);
See also

Definition at line 68 of file storage_mock.hpp.

Public Member Functions

 StorageMock ()
 Create an empty StorageMock
 StorageMock (std::initializer_list< KeyValue > config_variables)
 StorageMock (const std::vector< KeyValue > &config_variables)
 Only store config_variables in the Config
 StorageMock (const DocsMap &defaults, const std::vector< KeyValue > &overrides)
 Store overrides in the Config, then parse all the remaining variables from defaults
 StorageMock (StorageMock &&) noexcept
StorageMockoperator= (StorageMock &&) noexcept
void Extend (const std::vector< KeyValue > &overrides)
 Update some config variables.
Source GetSource () const &
Snapshot GetSnapshot () const &
Snapshot GetSource () &&=delete
Snapshot GetSnapshot () &&=delete

Constructor & Destructor Documentation

◆ StorageMock() [1/2]

dynamic_config::StorageMock::StorageMock ( std::initializer_list< KeyValue > config_variables)

Only store config_variables in the Config. Use as: StorageMock{{kVariableKey1, value1}, {kVariableKey2, value2}}

◆ StorageMock() [2/2]

dynamic_config::StorageMock::StorageMock ( const DocsMap & defaults,
const std::vector< KeyValue > & overrides )

Store overrides in the Config, then parse all the remaining variables from defaults

See also

The documentation for this class was generated from the following file: