summaryrefslogtreecommitdiff
path: root/tests/i2p_functions.rs
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-12-01 14:06:10 +0300
committerNamilskyy <alive6863@gmail.com>2025-12-01 14:06:10 +0300
commit068eea55e0612184151461e64633b3dc18e53490 (patch)
treed3e20aea860a88e2b50ad3d35ddbd8792a1e531e /tests/i2p_functions.rs
parent2029c2c09284d0228c0bce2977fdfa0ca8a8db06 (diff)
Implemented test suite, fixed some issues and added more modular structure into .woodpecker.yaml
Diffstat (limited to 'tests/i2p_functions.rs')
-rw-r--r--tests/i2p_functions.rs101
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/i2p_functions.rs b/tests/i2p_functions.rs
new file mode 100644
index 0000000..6b24d14
--- /dev/null
+++ b/tests/i2p_functions.rs
@@ -0,0 +1,101 @@
+use mesk::pkgtoolkit::pkgtools::{Package, Archs};
+use mesk::net::i2p_package::I2PPackage;
+
+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<dyn std::error::Error>> { ... }
+ // #[test]
+ // fn test_parse_http_response() { ... }
+ /*
+ #[tokio::test]
+ async fn test_i2p_fetch_index_success() -> Result<(), Box<dyn std::error::Error>> {
+ 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<dyn std::error::Error>> {
+ 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(),
+ };
+ 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<dyn std::error::Error>> {
+ 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(())
+ }
+}