1+ #include < gmock/gmock.h>
2+ #include < gtest/gtest.h>
3+ #include < filesystem>
4+ #include " utils/config_yaml_utils.h"
5+ #include " utils/file_manager_utils.h"
6+
7+ // Mock for filesystem operations
8+
9+ // Test fixture
10+ class FileManagerConfigTest : public ::testing::Test {};
11+
12+ // Tests for file_manager_utils
13+
14+ TEST_F (FileManagerConfigTest, GetExecutableFolderContainerPath) {
15+ auto path = file_manager_utils::GetExecutableFolderContainerPath ();
16+ EXPECT_FALSE (path.empty ());
17+ EXPECT_TRUE (std::filesystem::is_directory (path));
18+ }
19+
20+ TEST_F (FileManagerConfigTest, GetHomeDirectoryPath) {
21+ auto path = file_manager_utils::GetHomeDirectoryPath ();
22+ EXPECT_FALSE (path.empty ());
23+ EXPECT_TRUE (std::filesystem::is_directory (path));
24+ }
25+
26+ TEST_F (FileManagerConfigTest, GetConfigurationPath) {
27+ auto path = file_manager_utils::GetConfigurationPath ();
28+ EXPECT_FALSE (path.empty ());
29+ EXPECT_TRUE (path.has_filename ());
30+ }
31+
32+ TEST_F (FileManagerConfigTest, GetDefaultDataFolderName) {
33+ auto folder_name = file_manager_utils::GetDefaultDataFolderName ();
34+ EXPECT_FALSE (folder_name.empty ());
35+ EXPECT_TRUE (folder_name.find (" cortexcpp" ) != std::string::npos);
36+ }
37+
38+ TEST_F (FileManagerConfigTest, CreateConfigFileIfNotExist) {
39+
40+ file_manager_utils::CreateConfigFileIfNotExist ();
41+ EXPECT_TRUE (
42+ std::filesystem::exists (file_manager_utils::GetConfigurationPath ()));
43+ std::filesystem::remove (file_manager_utils::GetConfigurationPath ());
44+ }
45+
46+ TEST_F (FileManagerConfigTest, GetCortexConfig) {
47+ file_manager_utils::CreateConfigFileIfNotExist ();
48+ auto config = file_manager_utils::GetCortexConfig ();
49+ EXPECT_FALSE (config.dataFolderPath .empty ());
50+ EXPECT_FALSE (config.logFolderPath .empty ());
51+ EXPECT_GT (config.maxLogLines , 0 );
52+ }
53+
54+ // Tests for config_yaml_utils
55+
56+ TEST_F (FileManagerConfigTest, DumpYamlConfig) {
57+ config_yaml_utils::CortexConfig config{.logFolderPath = " /path/to/logs" ,
58+ .dataFolderPath = " /path/to/data" ,
59+ .maxLogLines = 1000 ,
60+ .apiServerHost = " localhost" ,
61+ .apiServerPort = " 8080" };
62+
63+ std::string test_file = " test_config.yaml" ;
64+ config_yaml_utils::DumpYamlConfig (config, test_file);
65+
66+ EXPECT_TRUE (std::filesystem::exists (test_file));
67+
68+ // Clean up
69+ std::filesystem::remove (test_file);
70+ }
71+
72+ TEST_F (FileManagerConfigTest, FromYaml) {
73+ // Create a test YAML file
74+ std::string test_file = " test_config.yaml" ;
75+ std::ofstream out_file (test_file);
76+ out_file << " logFolderPath: /path/to/logs\n "
77+ << " dataFolderPath: /path/to/data\n "
78+ << " maxLogLines: 1000\n "
79+ << " apiServerHost: localhost\n "
80+ << " apiServerPort: '8080'\n " ;
81+ out_file.close ();
82+
83+ config_yaml_utils::CortexConfig default_config{};
84+ auto config = config_yaml_utils::FromYaml (test_file, default_config);
85+
86+ EXPECT_EQ (config.logFolderPath , " /path/to/logs" );
87+ EXPECT_EQ (config.dataFolderPath , " /path/to/data" );
88+ EXPECT_EQ (config.maxLogLines , 1000 );
89+ EXPECT_EQ (config.apiServerHost , " localhost" );
90+ EXPECT_EQ (config.apiServerPort , " 8080" );
91+
92+ // Clean up
93+ std::filesystem::remove (test_file);
94+ }
0 commit comments