diff --git a/engine/e2e-test/main.py b/engine/e2e-test/main.py index d59466d29..9ef27c8dc 100644 --- a/engine/e2e-test/main.py +++ b/engine/e2e-test/main.py @@ -4,6 +4,8 @@ from test_cli_engine_install import TestCliEngineInstall from test_cli_engine_list import TestCliEngineList from test_cli_engine_uninstall import TestCliEngineUninstall +from test_cli_server_start import TestCliServerStart +from test_create_log_folder import TestCreateLogFolder if __name__ == "__main__": pytest.main([__file__, "-v"]) diff --git a/engine/e2e-test/test_cli_server_start.py b/engine/e2e-test/test_cli_server_start.py new file mode 100644 index 000000000..abe236cd0 --- /dev/null +++ b/engine/e2e-test/test_cli_server_start.py @@ -0,0 +1,24 @@ +import platform +import os +import pytest, requests +from test_runner import run +from test_runner import start_server, stop_server + + +class TestCliServerStart: + + @pytest.fixture(autouse=True) + def setup_and_teardown(self): + # Setup + success = start_server() + if not success: + raise Exception("Failed to start server") + + yield + + # Teardown + stop_server() + + def test_server_start_cli_run_successfully(self): + response = requests.get("http://localhost:3928/healthz") + assert response.status_code == 200 diff --git a/engine/e2e-test/test_create_log_folder.py b/engine/e2e-test/test_create_log_folder.py new file mode 100644 index 000000000..3d0236cd7 --- /dev/null +++ b/engine/e2e-test/test_create_log_folder.py @@ -0,0 +1,27 @@ +import platform +import os +from pathlib import Path +import pytest, requests, shutil +from test_runner import run +from test_runner import start_server, stop_server + + +class TestCreateLogFolder: + @pytest.fixture(autouse=True) + def setup_and_teardown(self): + # Setup + root = Path.home() + if os.path.exists(root / "cortexcpp" / "logs"): + shutil.rmtree(root / "cortexcpp" / "logs") + success = start_server() + if not success: + raise Exception("Failed to start server") + + yield + + # Teardown + stop_server() + + def test_create_log_folder_run_successfully(self): + root = Path.home() + assert os.path.exists(root / "cortexcpp" / "logs") diff --git a/engine/main.cc b/engine/main.cc index 949f9e0d2..38dd3791b 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -31,8 +31,8 @@ void RunServer() { << " Port: " << config.apiServerPort << "\n"; // Create logs/ folder and setup log to file - std::filesystem::create_directory(config.logFolderPath + "/" + - cortex_utils::logs_folder); + std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) / + std::filesystem::path(cortex_utils::logs_folder)); trantor::FileLogger asyncFileLogger; asyncFileLogger.setFileName(config.logFolderPath + "/" + cortex_utils::logs_base_name); @@ -160,6 +160,8 @@ int main(int argc, char* argv[]) { return 0; } else { auto config = file_manager_utils::GetCortexConfig(); + std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) / + std::filesystem::path(cortex_utils::logs_folder)); trantor::FileLogger asyncFileLogger; asyncFileLogger.setFileName(config.logFolderPath + "/" + cortex_utils::logs_cli_base_name);