{
TestConfig testConfig;
- BOOST_REQUIRE_NO_THROW(loadFromString(jsonTestString, testConfig));
+ BOOST_REQUIRE_NO_THROW(loadFromJsonString(jsonTestString, testConfig));
BOOST_CHECK_EQUAL(12345, testConfig.intVal);
BOOST_CHECK_EQUAL(-1234567890123456789ll, testConfig.int64Val);
BOOST_AUTO_TEST_CASE(ToStringTest)
{
TestConfig testConfig;
- BOOST_REQUIRE_NO_THROW(loadFromString(jsonTestString, testConfig));
+ BOOST_REQUIRE_NO_THROW(loadFromJsonString(jsonTestString, testConfig));
- std::string out = saveToString(testConfig);
+ std::string out = saveToJsonString(testConfig);
BOOST_CHECK_EQUAL(out, jsonTestString);
TestConfig::SubConfigOption unionConfig;
- BOOST_CHECK_THROW(saveToString(unionConfig), ConfigException);
+ BOOST_CHECK_THROW(saveToJsonString(unionConfig), ConfigException);
}
namespace loadErrorsTest {
using namespace loadErrorsTest;
IntConfig config;
- BOOST_REQUIRE_NO_THROW(loadFromString("{\"field\":1}", config));
+ BOOST_REQUIRE_NO_THROW(loadFromJsonString("{\"field\":1}", config));
- BOOST_CHECK_THROW(loadFromString("", config), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{", config), ConfigException); // invalid json
- BOOST_CHECK_THROW(loadFromString("{}", config), ConfigException); // missing field
+ BOOST_CHECK_THROW(loadFromJsonString("", config), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{", config), ConfigException); // invalid json
+ BOOST_CHECK_THROW(loadFromJsonString("{}", config), ConfigException); // missing field
// invalid type
IntConfig intConfig;
- BOOST_CHECK_NO_THROW(loadFromString("{\"field\": 1}", intConfig));
- BOOST_CHECK_THROW(loadFromString("{\"field\": \"1\"}", intConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1.0}", intConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": true}", intConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": []}", intConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": {}}", intConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1234567890123456789}", intConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": -1234567890123456789}", intConfig), ConfigException);
+ BOOST_CHECK_NO_THROW(loadFromJsonString("{\"field\": 1}", intConfig));
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": \"1\"}", intConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1.0}", intConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": true}", intConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": []}", intConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": {}}", intConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1234567890123456789}", intConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": -1234567890123456789}", intConfig), ConfigException);
StringConfig stringConfig;
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1}", stringConfig), ConfigException);
- BOOST_CHECK_NO_THROW(loadFromString("{\"field\": \"1\"}", stringConfig));
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1.0}", stringConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": true}", stringConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": []}", stringConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": {}}", stringConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1}", stringConfig), ConfigException);
+ BOOST_CHECK_NO_THROW(loadFromJsonString("{\"field\": \"1\"}", stringConfig));
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1.0}", stringConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": true}", stringConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": []}", stringConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": {}}", stringConfig), ConfigException);
DoubleConfig doubleConfig;
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1}", doubleConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": \"1\"}", doubleConfig), ConfigException);
- BOOST_CHECK_NO_THROW(loadFromString("{\"field\": 1.0}", doubleConfig));
- BOOST_CHECK_THROW(loadFromString("{\"field\": true}", doubleConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": []}", doubleConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": {}}", doubleConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1}", doubleConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": \"1\"}", doubleConfig), ConfigException);
+ BOOST_CHECK_NO_THROW(loadFromJsonString("{\"field\": 1.0}", doubleConfig));
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": true}", doubleConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": []}", doubleConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": {}}", doubleConfig), ConfigException);
BoolConfig boolConfig;
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1}", boolConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": \"1\"}", boolConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1.0}", boolConfig), ConfigException);
- BOOST_CHECK_NO_THROW(loadFromString("{\"field\": true}", boolConfig));
- BOOST_CHECK_THROW(loadFromString("{\"field\": []}", boolConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": {}}", boolConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1}", boolConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": \"1\"}", boolConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1.0}", boolConfig), ConfigException);
+ BOOST_CHECK_NO_THROW(loadFromJsonString("{\"field\": true}", boolConfig));
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": []}", boolConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": {}}", boolConfig), ConfigException);
ArrayConfig arrayConfig;
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1}", arrayConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": \"1\"}", arrayConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1.0}", arrayConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": true}", arrayConfig), ConfigException);
- BOOST_CHECK_NO_THROW(loadFromString("{\"field\": []}", arrayConfig));
- BOOST_CHECK_THROW(loadFromString("{\"field\": {}}", arrayConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1}", arrayConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": \"1\"}", arrayConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1.0}", arrayConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": true}", arrayConfig), ConfigException);
+ BOOST_CHECK_NO_THROW(loadFromJsonString("{\"field\": []}", arrayConfig));
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": {}}", arrayConfig), ConfigException);
ObjectConfig objectConfig;
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1}", objectConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": \"1\"}", objectConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": 1.0}", objectConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": true}", objectConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": []}", objectConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"field\": {}}", objectConfig), ConfigException);
- BOOST_CHECK_NO_THROW(loadFromString("{\"field\": {\"field\": 1}}", objectConfig));
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1}", objectConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": \"1\"}", objectConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": 1.0}", objectConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": true}", objectConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": []}", objectConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"field\": {}}", objectConfig), ConfigException);
+ BOOST_CHECK_NO_THROW(loadFromJsonString("{\"field\": {\"field\": 1}}", objectConfig));
UnionConfig unionConfig;
- BOOST_CHECK_THROW(loadFromString("{\"type\": \"long\", \"value\": 1}", unionConfig), ConfigException);
- BOOST_CHECK_THROW(loadFromString("{\"type\": \"int\"}", unionConfig), ConfigException);
- BOOST_CHECK_NO_THROW(loadFromString("{\"type\": \"int\", \"value\": 1}", unionConfig));
- BOOST_CHECK_NO_THROW(loadFromString("{\"type\": \"bool\", \"value\": true}", unionConfig));
+ BOOST_CHECK_THROW(loadFromJsonString("{\"type\": \"long\", \"value\": 1}", unionConfig), ConfigException);
+ BOOST_CHECK_THROW(loadFromJsonString("{\"type\": \"int\"}", unionConfig), ConfigException);
+ BOOST_CHECK_NO_THROW(loadFromJsonString("{\"type\": \"int\", \"value\": 1}", unionConfig));
+ BOOST_CHECK_NO_THROW(loadFromJsonString("{\"type\": \"bool\", \"value\": true}", unionConfig));
}
namespace hasVisitableTest {
BOOST_AUTO_TEST_CASE(FromToKVStoreTest)
{
TestConfig config;
- loadFromString(jsonTestString, config);
+ loadFromJsonString(jsonTestString, config);
std::string dbPath = fs::unique_path("/tmp/kvstore-%%%%.db3").string();
- saveToKVStore(dbPath, config);
+ saveToKVStore(dbPath, config, "prefix");
TestConfig outConfig;
- loadFromKVStore(dbPath, outConfig);
+ loadFromKVStore(dbPath, outConfig, "prefix");
- std::string out = saveToString(outConfig);
+ std::string out = saveToJsonString(outConfig);
BOOST_CHECK_EQUAL(out, jsonTestString);
fs::remove(dbPath);
BOOST_AUTO_TEST_CASE(FromToFDTest)
{
TestConfig config;
- loadFromString(jsonTestString, config);
+ loadFromJsonString(jsonTestString, config);
// Setup fd
std::string fifoPath = fs::unique_path("/tmp/fdstore-%%%%").string();
BOOST_CHECK(::mkfifo(fifoPath.c_str(), S_IWUSR | S_IRUSR) >= 0);
saveToFD(fd, config);
TestConfig outConfig;
loadFromFD(fd, outConfig);
- std::string out = saveToString(outConfig);
+ std::string out = saveToJsonString(outConfig);
BOOST_CHECK_EQUAL(out, jsonTestString);
// Cleanup
BOOST_AUTO_TEST_CASE(ConfigUnionTest)
{
TestConfig testConfig;
- BOOST_REQUIRE_NO_THROW(loadFromString(jsonTestString, testConfig));
+ BOOST_REQUIRE_NO_THROW(loadFromJsonString(jsonTestString, testConfig));
BOOST_CHECK(testConfig.union1.is<int>());
BOOST_CHECK(!testConfig.union1.is<TestConfig::SubConfig>());
BOOST_CHECK_EQUAL(subConfig.intVal, 54321);
BOOST_CHECK(testConfig.unions[0].is<int>());
BOOST_CHECK(testConfig.unions[1].is<TestConfig::SubConfig>());
- std::string out = saveToString(testConfig);
+ std::string out = saveToJsonString(testConfig);
BOOST_CHECK_EQUAL(out, jsonTestString);
//Check copy
testConfig.unions.clear();
testConfig.unions = unions;
- out = saveToString(testConfig);
+ out = saveToJsonString(testConfig);
BOOST_CHECK_EQUAL(out, jsonTestString);
}
struct Fixture {
std::string dbPath;
+ std::string dbPrefix;
Fixture()
: dbPath(fs::unique_path("/tmp/kvstore-%%%%.db3").string())
+ , dbPrefix("conf")
{
fs::remove(dbPath);
}
void checkJsonConfig(const TestConfig& cfg, const std::string& json)
{
TestConfig cfg2;
- loadFromString(json, cfg2);
+ loadFromJsonString(json, cfg2);
BOOST_CHECK_EQUAL(cfg2.intVal, cfg.intVal);
BOOST_CHECK_EQUAL(cfg.int64Val, cfg.int64Val);
BOOST_CHECK_EQUAL(cfg2.boolVal, cfg.boolVal);
void checkKVConfig(const TestConfig& cfg, const std::string& db)
{
KVStore store(db);
- BOOST_CHECK_EQUAL(store.get<int>(".intVal"), cfg.intVal);
- BOOST_CHECK_EQUAL(store.get<int64_t>(".int64Val"), cfg.int64Val);
- BOOST_CHECK_EQUAL(store.get<bool>(".boolVal"), cfg.boolVal);
- BOOST_CHECK_EQUAL(store.get<std::string>(".stringVal"), cfg.stringVal);
- BOOST_CHECK_EQUAL(store.get<int>(".intVector"), cfg.intVector.size());
- BOOST_CHECK_EQUAL(store.get<int>(".subObj.intVal"), cfg.subObj.intVal);
+ BOOST_CHECK_EQUAL(store.get<int>("conf.intVal"), cfg.intVal);
+ BOOST_CHECK_EQUAL(store.get<int64_t>("conf.int64Val"), cfg.int64Val);
+ BOOST_CHECK_EQUAL(store.get<bool>("conf.boolVal"), cfg.boolVal);
+ BOOST_CHECK_EQUAL(store.get<std::string>("conf.stringVal"), cfg.stringVal);
+ BOOST_CHECK_EQUAL(store.get<int>("conf.intVector"), cfg.intVector.size());
+ BOOST_CHECK_EQUAL(store.get<int>("conf.subObj.intVal"), cfg.subObj.intVal);
}
BOOST_AUTO_TEST_CASE(ReadConfigDefaults)
{
TestConfig cfg;
- loadFromKVStoreWithJson(dbPath, jsonTestString, cfg);
+ loadFromKVStoreWithJson(dbPath, jsonTestString, cfg, dbPrefix);
checkJsonConfig(cfg, jsonTestString);
}
BOOST_AUTO_TEST_CASE(ReadConfigNoDefaults)
{
TestConfig cfg;
- loadFromKVStoreWithJson(dbPath, jsonTestString, cfg);
+ loadFromKVStoreWithJson(dbPath, jsonTestString, cfg, dbPrefix);
// modify and save config
cfg.intVal += 5;
cfg.int64Val += 7777;
cfg.boolVal = !cfg.boolVal;
cfg.stringVal += "-changed";
- config::saveToKVStore(dbPath, cfg);
+ config::saveToKVStore(dbPath, cfg, dbPrefix);
TestConfig cfg2;
- loadFromKVStoreWithJson(dbPath, jsonTestString, cfg2);
+ loadFromKVStoreWithJson(dbPath, jsonTestString, cfg2, dbPrefix);
checkKVConfig(cfg2, dbPath);
}
""}));
config.units.push_back(unit);
- config::saveToFile(PROVISION_FILE_PATH.string(), config);
+ config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
ZoneProvision zoneProvision(ZONE_PATH.string(), {});
zoneProvision.start();
}
0,
0777}));
config.units.push_back(unit);
- config::saveToFile(PROVISION_FILE_PATH.string(), config);
+ config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
ZoneProvision zoneProvision(ZONE_PATH.string(), {});
zoneProvision.start();
O_CREAT,
0777}));
config.units.push_back(unit);
- config::saveToFile(PROVISION_FILE_PATH.string(), config);
+ config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
ZoneProvision zoneProvision(ZONE_PATH.string(), {});
zoneProvision.start();
unit.set(ZoneProvisioning::Link({PROVISION_FILE_PATH.string(),
linkFile.string()}));
config.units.push_back(unit);
- config::saveToFile(PROVISION_FILE_PATH.string(), config);
+ config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
{
ZoneProvision zoneProvision(ZONE_PATH.string(), {});
zoneProvision.start();
zoneProvision.declareFile(2, "path", 0747, 0777);
ZoneProvisioning config;
- BOOST_REQUIRE_NO_THROW(loadFromFile(PROVISION_FILE_PATH.string(), config));
+ BOOST_REQUIRE_NO_THROW(loadFromJsonFile(PROVISION_FILE_PATH.string(), config));
BOOST_REQUIRE_EQUAL(config.units.size(), 2);
BOOST_REQUIRE(config.units[0].is<ZoneProvisioning::File>());
BOOST_REQUIRE(config.units[1].is<ZoneProvisioning::File>());
zoneProvision.declareMount("/fake/path2", "/fake/path2", "tmpfs", 077, "fake");
ZoneProvisioning config;
- BOOST_REQUIRE_NO_THROW(loadFromFile(PROVISION_FILE_PATH.string(), config));
+ BOOST_REQUIRE_NO_THROW(loadFromJsonFile(PROVISION_FILE_PATH.string(), config));
BOOST_REQUIRE_EQUAL(config.units.size(), 2);
BOOST_REQUIRE(config.units[0].is<ZoneProvisioning::Mount>());
BOOST_REQUIRE(config.units[1].is<ZoneProvisioning::Mount>());
zoneProvision.declareLink("/fake/path2", "/fake/path2");
ZoneProvisioning config;
- BOOST_REQUIRE_NO_THROW(loadFromFile(PROVISION_FILE_PATH.string(), config));
+ BOOST_REQUIRE_NO_THROW(loadFromJsonFile(PROVISION_FILE_PATH.string(), config));
BOOST_REQUIRE_EQUAL(config.units.size(), 2);
BOOST_REQUIRE(config.units[0].is<ZoneProvisioning::Link>());
BOOST_REQUIRE(config.units[1].is<ZoneProvisioning::Link>());
0777}));
config.units.push_back(unit);
- config::saveToFile(PROVISION_FILE_PATH.string(), config);
+ config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
ZoneProvision zoneProvision(ZONE_PATH.string(), {"/tmp/"});
zoneProvision.start();