mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
refactor: Replace all old instances of Config with New Config (#1627)
Fixes #1184 Previous PR's found [here](https://github.com/XRPLF/clio/pull/1593) and [here](https://github.com/XRPLF/clio/pull/1544)
This commit is contained in:
@@ -26,6 +26,9 @@
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
using namespace util::config;
|
||||
|
||||
struct ObjectViewTest : testing::Test {
|
||||
@@ -38,17 +41,36 @@ struct ObjectViewTest : testing::Test {
|
||||
ClioConfigDefinition configData = generateConfig();
|
||||
};
|
||||
|
||||
TEST_F(ObjectViewTest, ObjectValueTest)
|
||||
TEST_F(ObjectViewTest, ObjectContainsKeyTest)
|
||||
{
|
||||
auto const headerObj = configData.getObject("header");
|
||||
EXPECT_FALSE(headerObj.containsKey("header"));
|
||||
EXPECT_TRUE(headerObj.containsKey("text1"));
|
||||
EXPECT_TRUE(headerObj.containsKey("port"));
|
||||
EXPECT_TRUE(headerObj.containsKey("admin"));
|
||||
}
|
||||
|
||||
EXPECT_EQ("value", headerObj.getValue("text1").asString());
|
||||
EXPECT_EQ(321, headerObj.getValue("port").asIntType<int>());
|
||||
EXPECT_EQ(false, headerObj.getValue("admin").asBool());
|
||||
TEST_F(ObjectViewTest, ObjectValueTest)
|
||||
{
|
||||
auto const headerObj = configData.getObject("header");
|
||||
EXPECT_EQ("value", headerObj.getValueView("text1").asString());
|
||||
EXPECT_EQ(321, headerObj.getValueView("port").asIntType<int>());
|
||||
EXPECT_EQ(false, headerObj.getValueView("admin").asBool());
|
||||
}
|
||||
|
||||
TEST_F(ObjectViewTest, ObjectGetValueByTemplateTest)
|
||||
{
|
||||
auto const headerObj = configData.getObject("header");
|
||||
EXPECT_EQ("value", headerObj.get<std::string>("text1"));
|
||||
EXPECT_EQ(321, headerObj.get<int>("port"));
|
||||
EXPECT_EQ(false, headerObj.get<bool>("admin"));
|
||||
}
|
||||
|
||||
TEST_F(ObjectViewTest, GetOptionalValue)
|
||||
{
|
||||
auto const optionalObj = configData.getObject("optional");
|
||||
EXPECT_EQ(std::nullopt, optionalObj.maybeValue<double>("withNoDefault"));
|
||||
EXPECT_EQ(0.0, optionalObj.maybeValue<double>("withDefault"));
|
||||
}
|
||||
|
||||
TEST_F(ObjectViewTest, ObjectValuesInArray)
|
||||
@@ -63,11 +85,11 @@ TEST_F(ObjectViewTest, ObjectValuesInArray)
|
||||
// object's key is only "sub" and "sub2"
|
||||
EXPECT_FALSE(firstObj.containsKey("array.[].sub"));
|
||||
|
||||
EXPECT_EQ(firstObj.getValue("sub").asDouble(), 111.11);
|
||||
EXPECT_EQ(firstObj.getValue("sub2").asString(), "subCategory");
|
||||
EXPECT_EQ(firstObj.getValueView("sub").asDouble(), 111.11);
|
||||
EXPECT_EQ(firstObj.getValueView("sub2").asString(), "subCategory");
|
||||
|
||||
EXPECT_EQ(secondObj.getValue("sub").asDouble(), 4321.55);
|
||||
EXPECT_EQ(secondObj.getValue("sub2").asString(), "temporary");
|
||||
EXPECT_EQ(secondObj.getValueView("sub").asDouble(), 4321.55);
|
||||
EXPECT_EQ(secondObj.getValueView("sub2").asString(), "temporary");
|
||||
}
|
||||
|
||||
TEST_F(ObjectViewTest, GetObjectsInDifferentWays)
|
||||
@@ -79,15 +101,15 @@ TEST_F(ObjectViewTest, GetObjectsInDifferentWays)
|
||||
|
||||
// this returns the 1st object inside "low"
|
||||
ObjectView const sameObjFromConfigData = configData.getObject("higher.[].low", 0);
|
||||
EXPECT_EQ(sameObjFromConfigData.getValue("admin").asBool(), firstObj.getValue("low.admin").asBool());
|
||||
EXPECT_EQ(sameObjFromConfigData.getValueView("admin").asBool(), firstObj.getValueView("low.admin").asBool());
|
||||
EXPECT_FALSE(firstObj.containsKey("low"));
|
||||
EXPECT_TRUE(firstObj.containsKey("low.admin"));
|
||||
|
||||
ObjectView const objLow = firstObj.getObject("low");
|
||||
EXPECT_TRUE(objLow.containsKey("section"));
|
||||
EXPECT_TRUE(objLow.containsKey("admin"));
|
||||
EXPECT_EQ(objLow.getValue("section").asString(), "WebServer");
|
||||
EXPECT_EQ(objLow.getValue("admin").asBool(), false);
|
||||
EXPECT_EQ(objLow.getValueView("section").asString(), "WebServer");
|
||||
EXPECT_EQ(objLow.getValueView("admin").asBool(), false);
|
||||
}
|
||||
|
||||
TEST_F(ObjectViewTest, getArrayInObject)
|
||||
@@ -120,3 +142,9 @@ TEST_F(ObjectViewDeathTest, KeyisArrayView)
|
||||
// dies because only 1 object in higher.[].low
|
||||
EXPECT_DEATH({ [[maybe_unused]] auto _ = configData.getObject("higher.[].low", 1); }, ".*");
|
||||
}
|
||||
|
||||
TEST_F(ObjectViewDeathTest, KeyisNotOptional)
|
||||
{
|
||||
// dies because not an optional
|
||||
EXPECT_DEATH({ [[maybe_unused]] auto _ = configData.getObject("header").maybeValue<std::string>("text1"); }, ".*");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user