use mesk::net::i2p_package::I2PPackage; use mesk::pkgtoolkit::{Archs, Package}; mod shared; use shared::create_test_config; use std::collections::HashMap; use tempfile::TempDir; use tokio; #[cfg(test)] mod i2p_package_tests { use super::*; // fn parse_http_response(response_bytes: &[u8]) -> Result<(u16, &[u8]), Box> { ... } // #[test] // fn test_parse_http_response() { ... } /* #[tokio::test] async fn test_i2p_fetch_index_success() -> Result<(), Box> { let temp_config_dir = TempDir::new()?; let config = create_test_config(temp_config_dir.path().to_str().unwrap()); let mut config_with_mock_url = config.clone(); config_with_mock_url.repo.repo_url = "http://dummy.i2p/repo"; let mut mock_session = MockSession::new(); mock_session .expect_connect() .with(eq("dummy.i2p")) .returning(|_| { // Возвращаем мок-поток, который возвращает байты архива let index_toml_content = r#"[[packages]] name = "test-pkg" ... "#; let mut archive_data = Vec::new(); // ... заполняем archive_data как в test_http_fetch_index_success ... let response_body = format!( "HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}", archive_data.len(), std::str::from_utf8(&archive_data).unwrap() ).into_bytes(); Ok(MockStream::new(response_body)) }); let mut i2p_pkg = I2PPackage::new_with_session(config_with_mock_url, Box::new(mock_session)); let result = i2p_pkg.fetch_index().await; assert!(result.is_ok()); Ok(()) } */ #[tokio::test] async fn test_i2p_fetch_package_info_success() -> Result<(), Box> { let temp_config_dir = TempDir::new()?; let config = create_test_config(temp_config_dir.path().to_str().unwrap()); let mut i2p_pkg = I2PPackage::new(config); let mut packages_map = HashMap::new(); let pkg = Package { name: "test-pkg".to_string(), version: "1.0.0".to_string(), arch: Archs::X86_64, descr: Some("Test".to_string()), license: Some("MIT".to_string()), url: "http://example.i2p/repo/test-pkg.mesk".to_string(), git_repo: None, }; packages_map.insert("test-pkg".to_string(), pkg); i2p_pkg.index_packages = Some(packages_map); let pkg_info = i2p_pkg.fetch_package_info("test-pkg"); assert!(pkg_info.is_ok()); assert_eq!(pkg_info.unwrap().name, "test-pkg"); Ok(()) } #[tokio::test] async fn test_i2p_fetch_package_info_not_found() -> Result<(), Box> { let temp_config_dir = TempDir::new()?; let config = create_test_config(temp_config_dir.path().to_str().unwrap()); let i2p_pkg = I2PPackage::new(config.clone()); // index_packages = None let result = i2p_pkg.fetch_package_info("nonexistent-pkg"); assert!(result.is_err()); let err_msg = result.unwrap_err().to_string(); assert!(err_msg.contains("Index not loaded")); let mut i2p_pkg_empty_index = I2PPackage::new(config); i2p_pkg_empty_index.index_packages = Some(HashMap::new()); let result_empty = i2p_pkg_empty_index.fetch_package_info("nonexistent-pkg"); assert!(result_empty.is_err()); let err_msg_empty = result_empty.unwrap_err().to_string(); assert!(err_msg_empty.contains("not found in index")); Ok(()) } }