szaszm commented on code in PR #1543: URL: https://github.com/apache/nifi-minifi-cpp/pull/1543#discussion_r1158383457
########## extensions/standard-processors/tests/unit/ConfigurationTests.cpp: ########## @@ -53,4 +54,130 @@ TEST_CASE("Configuration can validate values to be assigned to specific properti REQUIRE(Configuration::validatePropertyValue("random.property", "random_value")); } +TEST_CASE("Configuration can fix misconfigured timeperiod<->integer validated properties") { + LogTestController::getInstance().setInfo<minifi::Configure>(); + LogTestController::getInstance().setInfo<minifi::Properties>(); + + auto properties_path = std::filesystem::temp_directory_path() / "test.properties"; + + { + std::ofstream properties_file(properties_path); + properties_file << "nifi.c2.agent.heartbeat.period=1min" << std::endl; + properties_file << "nifi.administrative.yield.duration=30000" << std::endl; + properties_file.close(); + } + auto properties_file_time_after_creation = std::filesystem::last_write_time(properties_path); + const std::shared_ptr<minifi::Configure> configure = std::make_shared<minifi::Configure>(); + + configure->loadConfigureFile(properties_path); + CHECK(configure->get("nifi.c2.agent.heartbeat.period") == "60000"); + CHECK(configure->get("nifi.administrative.yield.duration") == "30000 ms"); + + { + CHECK(properties_file_time_after_creation == std::filesystem::last_write_time(properties_path)); + std::ifstream properties_file(properties_path); + std::string first_line; + std::string second_line; + CHECK(std::getline(properties_file, first_line)); + CHECK(std::getline(properties_file, second_line)); + CHECK(first_line == "nifi.c2.agent.heartbeat.period=1min"); + CHECK(second_line == "nifi.administrative.yield.duration=30000"); + } + + CHECK(configure->commitChanges()); + + { + CHECK(properties_file_time_after_creation <= std::filesystem::last_write_time(properties_path)); + std::ifstream properties_file(properties_path); + std::string first_line; + std::string second_line; + CHECK(std::getline(properties_file, first_line)); + CHECK(std::getline(properties_file, second_line)); + CHECK(first_line == "nifi.c2.agent.heartbeat.period=60000"); + CHECK(second_line == "nifi.administrative.yield.duration=30000 ms"); + } +} + +TEST_CASE("Configuration can fix misconfigured datasize<->integer validated properties") { + LogTestController::getInstance().setInfo<minifi::Configure>(); + LogTestController::getInstance().setInfo<minifi::Properties>(); + + auto properties_path = std::filesystem::temp_directory_path() / "test.properties"; + + { + std::ofstream properties_file(properties_path); + properties_file << "appender.rolling.max_file_size=6000" << std::endl; + properties_file.close(); + } + auto properties_file_time_after_creation = std::filesystem::last_write_time(properties_path); + const std::shared_ptr<minifi::Configure> configure = std::make_shared<minifi::Configure>(); + + configure->loadConfigureFile(properties_path, "nifi.log."); + CHECK(configure->get("appender.rolling.max_file_size") == "6000 B"); + + { + CHECK(properties_file_time_after_creation <= std::filesystem::last_write_time(properties_path)); + std::ifstream properties_file(properties_path); + std::string first_line; + CHECK(std::getline(properties_file, first_line)); + CHECK(first_line == "appender.rolling.max_file_size=6000"); + } + + CHECK(configure->commitChanges()); + + { + CHECK(properties_file_time_after_creation <= std::filesystem::last_write_time(properties_path)); + std::ifstream properties_file(properties_path); + std::string first_line; + CHECK(std::getline(properties_file, first_line)); + CHECK(first_line == "appender.rolling.max_file_size=6000 B"); + } +} + + +TEST_CASE("Configuration can fix misconfigured validated properties within environmental variables") { + LogTestController::getInstance().setInfo<minifi::Configure>(); + LogTestController::getInstance().setInfo<minifi::Properties>(); + auto properties_path = std::filesystem::temp_directory_path() / "test.properties"; + + CHECK(minifi::utils::Environment::setEnvironmentVariable("SOME_VARIABLE", "4000")); + + { + std::ofstream properties_file(properties_path); + properties_file << "compression.cached.log.max.size=${SOME_VARIABLE}" << std::endl; + properties_file << "compression.compressed.log.max.size=3000" << std::endl; + properties_file.close(); + } Review Comment: `std::endl` flushes the stream. I think it's not necessary, but certainly not twice. ```suggestion std::ofstream{properties_path} << "compression.cached.log.max.size=${SOME_VARIABLE}\n" << "compression.compressed.log.max.size=3000\n"; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org