summaryrefslogtreecommitdiff
path: root/tests/pkgtoolkit_funcs.rs
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-12-01 14:17:47 +0300
committerNamilskyy <alive6863@gmail.com>2025-12-01 14:17:47 +0300
commitb157e34176858766738be7e6903cc188285a5aeb (patch)
tree5a58fbb2eda53cb4c3fd131f2457fb9639285ad6 /tests/pkgtoolkit_funcs.rs
parent3fc368fbd6a818a8f9f210c995d82725d11e6e45 (diff)
Formatted code && fix clippy warn
Diffstat (limited to 'tests/pkgtoolkit_funcs.rs')
-rw-r--r--tests/pkgtoolkit_funcs.rs31
1 files changed, 10 insertions, 21 deletions
diff --git a/tests/pkgtoolkit_funcs.rs b/tests/pkgtoolkit_funcs.rs
index ae0c4d7..667592d 100644
--- a/tests/pkgtoolkit_funcs.rs
+++ b/tests/pkgtoolkit_funcs.rs
@@ -1,13 +1,11 @@
-use mesk::pkgtoolkit::pkgtools::{Package, Archs};
-
+use mesk::pkgtoolkit::pkgtools::{Archs, Package};
mod shared;
use shared::create_test_config;
-use tempfile::TempDir;
+use tempfile::TempDir;
use tokio;
-
// Pkg toolkit tests
#[cfg(test)]
mod package_tests {
@@ -29,7 +27,6 @@ mod package_tests {
let temp_dir = TempDir::new()?;
let _config = create_test_config(temp_dir.path().to_str().unwrap());
-
let test_file_content = "test content";
let test_file_path = temp_dir.path().join("test_file.txt");
fs::write(&test_file_path, test_file_content)?;
@@ -41,10 +38,8 @@ mod package_tests {
tar_builder.append_path_with_name(&test_file_path, "extracted_test_file.txt")?;
tar_builder.into_inner()?.finish()?;
-
Package::extract_archive(archive_path.to_str().unwrap())?;
-
let extracted_file_path = temp_dir.path().join("extracted_test_file.txt");
assert!(extracted_file_path.exists());
let content = fs::read_to_string(extracted_file_path)?;
@@ -53,13 +48,11 @@ mod package_tests {
Ok(())
}
-
#[tokio::test]
async fn test_package_check_valid() -> Result<(), Box<dyn std::error::Error>> {
let temp_dir = TempDir::new()?;
let _config = create_test_config(temp_dir.path().to_str().unwrap());
-
let install_content = r#"
[package]
name = "test-pkg"
@@ -79,7 +72,6 @@ mode = "755"
let mut install_file = fs::File::create(&install_path)?;
install_file.write_all(install_content.as_bytes())?;
-
let archive_path = temp_dir.path().join("test_pkg_with_install.tar.gz");
let file = fs::File::create(&archive_path)?;
let gz_encoder = flate2::write::GzEncoder::new(file, flate2::Compression::default());
@@ -95,7 +87,6 @@ mode = "755"
Ok(())
}
-
#[tokio::test]
async fn test_package_check_missing_install() -> Result<(), Box<dyn std::error::Error>> {
let temp_dir = TempDir::new()?;
@@ -119,13 +110,12 @@ mode = "755"
Ok(())
}
-
#[tokio::test]
async fn test_package_check_empty_install() -> Result<(), Box<dyn std::error::Error>> {
let temp_dir = TempDir::new()?;
let install_path = temp_dir.path().join("INSTALL");
- fs::write(&install_path, "")?;
+ fs::write(&install_path, "")?;
let archive_path = temp_dir.path().join("test_pkg_with_empty_install.tar.gz");
let file = fs::File::create(&archive_path)?;
let gz_encoder = flate2::write::GzEncoder::new(file, flate2::Compression::default());
@@ -133,7 +123,6 @@ mode = "755"
tar_builder.append_path_with_name(&install_path, "INSTALL")?;
tar_builder.into_inner()?.finish()?;
-
let result = Package::check(archive_path.to_str().unwrap().to_string());
assert!(result.is_err());
@@ -144,15 +133,15 @@ mode = "755"
Ok(())
}
-
#[tokio::test]
async fn test_package_check_arch_mismatch() -> Result<(), Box<dyn std::error::Error>> {
let temp_dir = TempDir::new()?;
let _config = create_test_config(temp_dir.path().to_str().unwrap());
let host_arch = std::env::consts::ARCH;
- let wrong_arch = if host_arch == "x86" { "x86_64" } else { "x86" };
- let install_content = format!(r#"
+ let wrong_arch = if host_arch == "x86" { "x86_64" } else { "x86" };
+ let install_content = format!(
+ r#"
[package]
name = "test-pkg"
version = "1.0.0"
@@ -166,7 +155,9 @@ path = "/tmp/test_binary"
user = "root"
group = "root"
mode = "755"
-"#, wrong_arch);
+"#,
+ wrong_arch
+ );
let install_path = temp_dir.path().join("INSTALL");
let mut install_file = fs::File::create(&install_path)?;
@@ -181,7 +172,6 @@ mode = "755"
let result = Package::check(archive_path.to_str().unwrap().to_string());
-
assert!(result.is_err());
let err = result.unwrap_err();
assert_eq!(err.kind(), std::io::ErrorKind::InvalidData);
@@ -189,5 +179,4 @@ mode = "755"
Ok(())
}
-
-} \ No newline at end of file
+}