Skip to content

Commit

Permalink
MINIFICPP-2288 Remove the caching of loggers (spdlog will do this for…
Browse files Browse the repository at this point in the history
… us anyway)
  • Loading branch information
martinzink committed Jan 18, 2024
1 parent 04575f0 commit bac5198
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 175 deletions.
15 changes: 7 additions & 8 deletions extensions/sftp/tests/FetchSFTPTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
class FetchSFTPTestsFixture {
public:
FetchSFTPTestsFixture() {
LogTestController::getInstance().reset();
LogTestController::getInstance().setTrace<TestPlan>();
LogTestController::getInstance().setDebug<minifi::FlowController>();
LogTestController::getInstance().setDebug<minifi::SchedulingAgent>();
Expand Down Expand Up @@ -110,12 +111,10 @@ class FetchSFTPTestsFixture {
FetchSFTPTestsFixture& operator=(FetchSFTPTestsFixture&&) = delete;
FetchSFTPTestsFixture& operator=(const FetchSFTPTestsFixture&) = delete;

virtual ~FetchSFTPTestsFixture() {
LogTestController::getInstance().reset();
}
virtual ~FetchSFTPTestsFixture() = default;

// Create source file
void createFile(const std::string& relative_path, const std::string& content) {
void createFile(const std::string& relative_path, const std::string& content) const {
const auto file_path = src_dir / "vfs" / relative_path;
std::filesystem::create_directories(file_path.parent_path());

Expand All @@ -130,8 +129,8 @@ class FetchSFTPTestsFixture {
IN_SOURCE
};

void testFile(TestWhere where, const std::filesystem::path& relative_path, std::string_view expected_content) {
std::filesystem::path expected_path = where == IN_DESTINATION ? dst_dir / relative_path : src_dir / "vfs" / relative_path;
void testFile(TestWhere where, const std::filesystem::path& relative_path, std::string_view expected_content) const {
const auto expected_path = where == IN_DESTINATION ? dst_dir / relative_path : src_dir / "vfs" / relative_path;
REQUIRE(std::filesystem::exists(expected_path));
std::filesystem::permissions(expected_path, static_cast<std::filesystem::perms>(0644));

Expand All @@ -146,8 +145,8 @@ class FetchSFTPTestsFixture {
CHECK(expected_content == content.str());
}

void testFileNotExists(TestWhere where, const std::string& relative_path) {
std::filesystem::path expected_path = where == IN_DESTINATION ? dst_dir / relative_path : src_dir / "vfs" / relative_path;
void testFileNotExists(TestWhere where, const std::string& relative_path) const {
const auto expected_path = where == IN_DESTINATION ? dst_dir / relative_path : src_dir / "vfs" / relative_path;
CHECK(!std::filesystem::exists(expected_path));
}

Expand Down
15 changes: 6 additions & 9 deletions extensions/sftp/tests/ListSFTPTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

#include "TestBase.h"
#include "Catch.h"
#include "utils/StringUtils.h"
#include "utils/file/FileUtils.h"
#include "core/Core.h"
#include "core/logging/Logger.h"
Expand All @@ -50,7 +49,6 @@
#include "processors/ListSFTP.h"
#include "processors/GenerateFlowFile.h"
#include "processors/LogAttribute.h"
#include "processors/UpdateAttribute.h"
#include "tools/SFTPTestServer.h"
#include "utils/TestUtils.h"

Expand All @@ -59,6 +57,7 @@ using namespace std::literals::chrono_literals;
class ListSFTPTestsFixture {
public:
explicit ListSFTPTestsFixture(const std::shared_ptr<minifi::Configure>& configuration = nullptr) {
LogTestController::getInstance().reset();
LogTestController::getInstance().setTrace<TestPlan>();
LogTestController::getInstance().setDebug<minifi::FlowController>();
LogTestController::getInstance().setDebug<minifi::SchedulingAgent>();
Expand Down Expand Up @@ -89,11 +88,9 @@ class ListSFTPTestsFixture {
ListSFTPTestsFixture& operator=(ListSFTPTestsFixture&&) = delete;
ListSFTPTestsFixture& operator=(const ListSFTPTestsFixture&) = delete;

virtual ~ListSFTPTestsFixture() {
LogTestController::getInstance().reset();
}
virtual ~ListSFTPTestsFixture() = default;

void createPlan(utils::Identifier* list_sftp_uuid = nullptr, const std::shared_ptr<minifi::Configure>& configuration = nullptr) {
void createPlan(const utils::Identifier* list_sftp_uuid = nullptr, const std::shared_ptr<minifi::Configure>& configuration = nullptr) {
const auto state_dir = plan == nullptr ? testController.createTempDirectory() : plan->getStateDir();

log_attribute.reset();
Expand Down Expand Up @@ -144,9 +141,9 @@ class ListSFTPTestsFixture {
}

// Create source file
void createFile(const std::filesystem::path& relative_path, const std::string& content, std::optional<std::chrono::file_clock::time_point> modification_time) {
void createFile(const std::filesystem::path& relative_path, const std::string& content, const std::optional<std::chrono::file_clock::time_point>& modification_time) const {
std::fstream file;
std::filesystem::path full_path = working_directory / "vfs" / relative_path;
const auto full_path = working_directory / "vfs" / relative_path;
std::filesystem::create_directories(full_path.parent_path());
file.open(full_path, std::ios::out);
file << content;
Expand All @@ -156,7 +153,7 @@ class ListSFTPTestsFixture {
}
}

void createFileWithModificationTimeDiff(const std::filesystem::path& relative_path, const std::string& content, std::chrono::seconds modification_timediff = -5min) {
void createFileWithModificationTimeDiff(const std::filesystem::path& relative_path, const std::string& content, std::chrono::seconds modification_timediff = -5min) const {
return createFile(relative_path, content, std::chrono::file_clock::now() + modification_timediff);
}

Expand Down
17 changes: 6 additions & 11 deletions extensions/sftp/tests/ListThenFetchSFTPTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@

#include "TestBase.h"
#include "Catch.h"
#include "utils/StringUtils.h"
#include "utils/file/FileUtils.h"
#include "core/Core.h"
#include "core/logging/Logger.h"
#include "core/ProcessGroup.h"
#include "FlowController.h"
#include "properties/Configure.h"
#include "unit/ProvenanceTestHelper.h"
#include "processors/FetchSFTP.h"
#include "processors/ListSFTP.h"
#include "processors/GenerateFlowFile.h"
#include "processors/LogAttribute.h"
#include "processors/UpdateAttribute.h"
#include "processors/PutFile.h"
#include "tools/SFTPTestServer.h"

Expand All @@ -57,6 +53,7 @@ using namespace std::literals::chrono_literals;
class ListThenFetchSFTPTestsFixture {
public:
ListThenFetchSFTPTestsFixture() {
LogTestController::getInstance().reset();
LogTestController::getInstance().setTrace<TestPlan>();
LogTestController::getInstance().setDebug<minifi::FlowController>();
LogTestController::getInstance().setDebug<minifi::SchedulingAgent>();
Expand Down Expand Up @@ -147,14 +144,12 @@ class ListThenFetchSFTPTestsFixture {
ListThenFetchSFTPTestsFixture& operator=(ListThenFetchSFTPTestsFixture&&) = delete;
ListThenFetchSFTPTestsFixture& operator=(const ListThenFetchSFTPTestsFixture&) = delete;

virtual ~ListThenFetchSFTPTestsFixture() {
LogTestController::getInstance().reset();
}
virtual ~ListThenFetchSFTPTestsFixture() = default;

// Create source file
void createFile(const std::string& relative_path, const std::string& content, std::optional<std::chrono::file_clock::time_point> modification_time) {
void createFile(const std::string& relative_path, const std::string& content, const std::optional<std::chrono::file_clock::time_point>& modification_time) const {
std::fstream file;
std::filesystem::path full_path = src_dir / "vfs" / relative_path;
const auto full_path = src_dir / "vfs" / relative_path;
std::filesystem::create_directories(full_path.parent_path());
file.open(full_path, std::ios::out);
file << content;
Expand All @@ -164,7 +159,7 @@ class ListThenFetchSFTPTestsFixture {
}
}

void createFileWithModificationTimeDiff(const std::string& relative_path, const std::string& content, std::chrono::seconds modification_timediff = -5min) {
void createFileWithModificationTimeDiff(const std::string& relative_path, const std::string& content, std::chrono::seconds modification_timediff = -5min) const {
return createFile(relative_path, content, std::chrono::file_clock::now() + modification_timediff);
}

Expand All @@ -173,7 +168,7 @@ class ListThenFetchSFTPTestsFixture {
IN_SOURCE
};

void testFile(TestWhere where, const std::filesystem::path& relative_path, std::string_view expected_content) {
void testFile(TestWhere where, const std::filesystem::path& relative_path, std::string_view expected_content) const {
std::filesystem::path expected_path = where == IN_DESTINATION ? dst_dir / relative_path : src_dir / "vfs" / relative_path;
REQUIRE(std::filesystem::exists(expected_path));
std::filesystem::permissions(expected_path, static_cast<std::filesystem::perms>(0644));;
Expand Down
44 changes: 20 additions & 24 deletions extensions/sftp/tests/PutSFTPTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,16 @@
#include "Catch.h"
#include "Exception.h"
#include "date/date.h"
#include "utils/StringUtils.h"
#include "utils/file/FileUtils.h"
#include "core/Core.h"
#include "core/logging/Logger.h"
#include "core/ProcessGroup.h"
#include "FlowController.h"
#include "properties/Configure.h"
#include "unit/ProvenanceTestHelper.h"
#include "processors/PutSFTP.h"
#include "processors/GetFile.h"
#include "processors/LogAttribute.h"
#include "processors/ExtractText.h"
#include "processors/UpdateAttribute.h"
#include "tools/SFTPTestServer.h"

constexpr const char* PUBLIC_KEY_AUTH_ERROR_MESSAGE = "Failed to authenticate with publickey, error: Unable to extract public key from private key file: Wrong passphrase or invalid/unrecognized private key file format"; // NOLINT(whitespace/line_length)
Expand All @@ -62,6 +59,7 @@ using namespace std::literals::chrono_literals;
class PutSFTPTestsFixture {
public:
PutSFTPTestsFixture() {
LogTestController::getInstance().reset();
LogTestController::getInstance().setTrace<TestPlan>();
LogTestController::getInstance().setDebug<minifi::FlowController>();
LogTestController::getInstance().setDebug<minifi::SchedulingAgent>();
Expand Down Expand Up @@ -124,9 +122,7 @@ class PutSFTPTestsFixture {
PutSFTPTestsFixture& operator=(PutSFTPTestsFixture&&) = delete;
PutSFTPTestsFixture& operator=(const PutSFTPTestsFixture&) = delete;

virtual ~PutSFTPTestsFixture() {
LogTestController::getInstance().reset();
}
virtual ~PutSFTPTestsFixture() = default;

// Create source file
static void createFile(const std::string &dir, const std::string& relative_path, const std::string& content) {
Expand All @@ -139,7 +135,7 @@ class PutSFTPTestsFixture {
}

// Test target file
void testFile(const std::string& relative_path, const std::string& expected_content) {
void testFile(const std::string& relative_path, const std::string& expected_content) const {
auto result_file = dst_dir / "vfs" / relative_path;
std::ifstream file(result_file);
REQUIRE(true == file.good());
Expand All @@ -152,36 +148,36 @@ class PutSFTPTestsFixture {
REQUIRE(expected_content == content.str());
}

void testFileNotExists(const std::string& relative_path) {
void testFileNotExists(const std::string& relative_path) const {
auto result_file = dst_dir / "vfs" / relative_path;
std::ifstream file(result_file);
REQUIRE(false == file.is_open());
REQUIRE(false == file.good());
}

void testModificationTime(const std::string& relative_path, std::chrono::file_clock::time_point mtime) {
auto result_file = dst_dir / "vfs" / relative_path;
void testModificationTime(const std::string& relative_path, std::chrono::file_clock::time_point mtime) const {
const auto result_file = dst_dir / "vfs" / relative_path;
REQUIRE(mtime == utils::file::last_write_time(result_file).value());
}

void testPermissions(const std::string& relative_path, uint32_t expected_permissions) {
auto result_file = dst_dir / "vfs" / relative_path;
void testPermissions(const std::string& relative_path, uint32_t expected_permissions) const {
const auto result_file = dst_dir / "vfs" / relative_path;
uint32_t permissions = 0U;
REQUIRE(true == utils::file::get_permissions(result_file, permissions));
REQUIRE(expected_permissions == permissions);
}

void testOwner(const std::string& relative_path, uint64_t expected_uid) {
auto result_file = dst_dir / "vfs" / relative_path;
void testOwner(const std::string& relative_path, uint64_t expected_uid) const {
const auto result_file = dst_dir / "vfs" / relative_path;

uint64_t uid = 0U;
uint64_t gid = 0U;
REQUIRE(true == utils::file::get_uid_gid(result_file, uid, gid));
REQUIRE(expected_uid == uid);
}

void testGroup(const std::string& relative_path, uint64_t expected_gid) {
auto result_file = dst_dir / "vfs" / relative_path;
void testGroup(const std::string& relative_path, uint64_t expected_gid) const {
const auto result_file = dst_dir / "vfs" / relative_path;

uint64_t uid = 0U;
uint64_t gid = 0U;
Expand Down Expand Up @@ -230,7 +226,7 @@ TEST_CASE_METHOD(PutSFTPTestsFixture, "PutSFTP bad password", "[PutSFTP][authent
try {
testController.runSession(plan, true);
} catch (std::exception &e) {
std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
const std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
REQUIRE(0 == std::string(e.what()).compare(0, expected.size(), expected));
}

Expand Down Expand Up @@ -260,7 +256,7 @@ TEST_CASE_METHOD(PutSFTPTestsFixture, "PutSFTP public key authentication bad pas
try {
testController.runSession(plan, true);
} catch (std::exception &e) {
std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
const std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
REQUIRE(0 == std::string(e.what()).compare(0, expected.size(), expected));
}
REQUIRE(LogTestController::getInstance().contains(PUBLIC_KEY_AUTH_ERROR_MESSAGE));
Expand Down Expand Up @@ -303,7 +299,7 @@ TEST_CASE_METHOD(PutSFTPTestsFixture, "PutSFTP host key checking missing strict"
try {
testController.runSession(plan, true);
} catch (std::exception &e) {
std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
const std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
REQUIRE(0 == std::string(e.what()).compare(0, expected.size(), expected));
}

Expand Down Expand Up @@ -333,7 +329,7 @@ TEST_CASE_METHOD(PutSFTPTestsFixture, "PutSFTP host key checking mismatch strict
try {
testController.runSession(plan, true);
} catch (std::exception &e) {
std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
const std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
REQUIRE(0 == std::string(e.what()).compare(0, expected.size(), expected));
}

Expand Down Expand Up @@ -501,7 +497,7 @@ TEST_CASE_METHOD(PutSFTPTestsFixture, "PutSFTP set mtime", "[PutSFTP]") {
testController.runSession(plan, true);

testFile("nifi_test/tstFile1.ext", "content 1");
std::chrono::system_clock::time_point modification_time = date::sys_days(date::January / 24 / 2065) + 5h + 20min;
constexpr auto modification_time = date::sys_days(date::January / 24 / 2065) + 5h + 20min;
testModificationTime("nifi_test/tstFile1.ext", utils::file::from_sys(modification_time));
}

Expand Down Expand Up @@ -663,13 +659,13 @@ TEST_CASE_METHOD(PutSFTPTestsFixture, "PutSFTP connection caching does not reuse
createFile(src_dir, "tstFile1.ext", "content 1");

/* Simulate connection failure */
auto port = sftp_server->getPort();
const auto port = sftp_server->getPort();
sftp_server.reset();

try {
testController.runSession(plan, true);
} catch (std::exception &e) {
std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
const std::string expected = minifi::Exception(minifi::PROCESS_SESSION_EXCEPTION, "Can not find the transfer relationship for the updated flow").what();
REQUIRE(0 == std::string(e.what()).compare(0, expected.size(), expected));
}

Expand Down Expand Up @@ -815,7 +811,7 @@ TEST_CASE_METHOD(PutSFTPTestsFixture, "PutSFTP expression language test", "[PutS
get_file = plan->addProcessor(
"GetFile",
"GetFile");
auto update_attribute = plan->addProcessor(
const auto update_attribute = plan->addProcessor(
"UpdateAttribute",
"UpdateAttribute",
core::Relationship("success", "d"),
Expand Down
Loading

0 comments on commit bac5198

Please sign in to comment.