summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authornamilsk <namilsk@namilsk.tech>2026-01-20 18:31:42 +0300
committernamilsk <namilsk@namilsk.tech>2026-01-20 18:33:30 +0300
commit2be31dc8ca78ecd91ef726c0fa4ca5129629076e (patch)
tree93320390eb21013df36c89171046abda5386afe1 /tests
parent6f2c288f81abcaffb5381fd868b5ef82f00c4816 (diff)
Shitcode, again
Diffstat (limited to 'tests')
-rw-r--r--tests/router_funcs.rs78
-rw-r--r--tests/router_integration_tests.rs94
2 files changed, 172 insertions, 0 deletions
diff --git a/tests/router_funcs.rs b/tests/router_funcs.rs
new file mode 100644
index 0000000..7d0cce8
--- /dev/null
+++ b/tests/router_funcs.rs
@@ -0,0 +1,78 @@
+use mesk::cfg::config::{Config, RouterConfig};
+use mesk::router::manager::RouterManager;
+
+#[tokio::test]
+async fn test_router_manager_creation() {
+ let config = Config {
+ repo: mesk::cfg::config::Repo {
+ repo_url: "https://mesk.anthrill.i2p/repo/x86_64/".to_string(),
+ auto_update: true,
+ destination: (String::from("mesk"), String::from("mesk")),
+ repo_http_url: Some("http://github.com/Anthrill/repo-mirror/x86_64".to_string()),
+ i2p_http_proxy_port: 4444,
+ },
+ log: mesk::cfg::config::Log {
+ log_file: "/tmp/mesk_test.log".to_string(),
+ log_level: mesk::cfg::config::Loglevel::Debug,
+ },
+ paths: mesk::cfg::config::Paths {
+ cache_dir: "/tmp/mesk_cache".to_string(),
+ build_dir: "/tmp/mesk_build".to_string(),
+ installed_db: "/tmp/mesk_pkgdb".to_string(),
+ },
+ router: RouterConfig {
+ integrated_router: false, // Disable router for this test to avoid conflicts
+ storage_path: "/tmp/mesk_test_router/".to_string(),
+ http_proxy_port: 4447,
+ socks_proxy_port: 4448,
+ auto_update: false,
+ },
+ };
+
+ let result = RouterManager::new(&config).await;
+ assert!(result.is_ok());
+
+ let manager = result.unwrap();
+ assert_eq!(manager.is_running(), false);
+}
+
+#[tokio::test]
+async fn test_router_manager_with_disabled_router() {
+ let config = Config {
+ repo: mesk::cfg::config::Repo {
+ repo_url: "https://mesk.anthrill.i2p/repo/x86_64/".to_string(),
+ auto_update: true,
+ destination: (String::from("mesk"), String::from("mesk")),
+ repo_http_url: Some("http://github.com/Anthrill/repo-mirror/x86_64".to_string()),
+ i2p_http_proxy_port: 4444,
+ },
+ log: mesk::cfg::config::Log {
+ log_file: "/tmp/mesk_test.log".to_string(),
+ log_level: mesk::cfg::config::Loglevel::Debug,
+ },
+ paths: mesk::cfg::config::Paths {
+ cache_dir: "/tmp/mesk_cache".to_string(),
+ build_dir: "/tmp/mesk_build".to_string(),
+ installed_db: "/tmp/mesk_pkgdb".to_string(),
+ },
+ router: RouterConfig {
+ integrated_router: false, // Explicitly disable router
+ storage_path: "/tmp/mesk_test_router/".to_string(),
+ http_proxy_port: 4447,
+ socks_proxy_port: 4448,
+ auto_update: false,
+ },
+ };
+
+ let result = RouterManager::new(&config).await;
+ assert!(result.is_ok());
+
+ let manager = result.unwrap();
+ // When router is disabled, we shouldn't be able to start it
+ let start_result = manager.start().await;
+ // This test checks that disabled router behaves properly
+ // Actual start operations may not work when integrated_router is false
+ println!("Router start result when disabled: {:?}", start_result);
+
+ assert_eq!(manager.is_running(), false);
+}
diff --git a/tests/router_integration_tests.rs b/tests/router_integration_tests.rs
new file mode 100644
index 0000000..bf534f5
--- /dev/null
+++ b/tests/router_integration_tests.rs
@@ -0,0 +1,94 @@
+use mesk::cfg::config::{Config, RouterConfig};
+use mesk::router::manager::RouterManager;
+
+// Integration tests for router functionality
+// Note: These tests use a minimal configuration to avoid actually starting a full router
+
+#[tokio::test]
+async fn test_router_start_functionality() {
+ let config = create_test_config(true); // Enable router for this test
+
+ let result = RouterManager::new(&config).await;
+ assert!(result.is_ok());
+
+ let manager = result.unwrap();
+
+ // Initially should not be running
+ assert_eq!(manager.is_running(), false);
+
+ // Attempt to start (this won't fully work without actual router dependencies)
+ let start_result = manager.start().await;
+ // This might fail due to missing dependencies, but the call should be accepted
+ println!("Start result: {:?}", start_result);
+}
+
+#[tokio::test]
+async fn test_router_stop_functionality() {
+ let config = create_test_config(true); // Enable router for this test
+
+ let result = RouterManager::new(&config).await;
+ assert!(result.is_ok());
+
+ let manager = result.unwrap();
+
+ // Test stopping when not running
+ manager.stop().await;
+ assert_eq!(manager.is_running(), false);
+}
+
+#[tokio::test]
+async fn test_router_restart_functionality() {
+ let config = create_test_config(true); // Enable router for this test
+
+ let result = RouterManager::new(&config).await;
+ assert!(result.is_ok());
+
+ let manager = result.unwrap();
+
+ // Test restart (this won't fully work without actual router dependencies)
+ let restart_result = manager.restart().await;
+ // This might fail due to missing dependencies, but the call should be accepted
+ println!("Restart result: {:?}", restart_result);
+}
+
+#[tokio::test]
+async fn test_router_status_functionality() {
+ let config = create_test_config(false); // Disable router for this test
+
+ let result = RouterManager::new(&config).await;
+ assert!(result.is_ok());
+
+ let manager = result.unwrap();
+
+ // Should not be running when router is disabled
+ assert_eq!(manager.is_running(), false);
+}
+
+// Helper function to create test configuration
+fn create_test_config(integrated_router_enabled: bool) -> Config {
+ Config {
+ repo: mesk::cfg::config::Repo {
+ repo_url: "https://mesk.anthrill.i2p/repo/x86_64/".to_string(),
+ auto_update: true,
+ destination: (String::from("mesk"), String::from("mesk")),
+ repo_http_url: Some("http://github.com/Anthrill/repo-mirror/x86_64".to_string()),
+ i2p_http_proxy_port: 4444,
+ },
+ log: mesk::cfg::config::Log {
+ log_file: "/tmp/mesk_test.log".to_string(),
+ log_level: mesk::cfg::config::Loglevel::Debug,
+ },
+ paths: mesk::cfg::config::Paths {
+ cache_dir: "/tmp/mesk_cache".to_string(),
+ build_dir: "/tmp/mesk_build".to_string(),
+ installed_db: "/tmp/mesk_pkgdb".to_string(),
+ },
+ router: RouterConfig {
+ integrated_router: integrated_router_enabled,
+ storage_path: "/tmp/mesk_test_router/".to_string(),
+ http_proxy_port: 4447,
+ socks_proxy_port: 4448,
+ auto_update: false,
+ },
+ }
+}