use crate::_test_support::remove_test_dir;
use crate::packer::{self};
use crate::runtime::Runtime;
use simple_fs::SPath;
use std::fs;
pub type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
#[tokio::test]
async fn test_packer_impl_pack_simple() -> Result<()> {
let runtime = Runtime::new_test_runtime_for_temp_dir()?;
let dir_context = runtime.dir_context();
let to_pack_dir = SPath::new("tests-data/test_packs_folder/test_pack_01");
let pack_result = packer::pack_dir(to_pack_dir, dir_context.current_dir())?;
verify_aipack_file(&pack_result.pack_file)?;
assert_eq!(pack_result.pack_toml.namespace, "test");
assert_eq!(pack_result.pack_toml.name, "test_pack_01");
assert_eq!(pack_result.pack_toml.version, "0.1.0");
let filename = pack_result.pack_file.name();
assert!(
filename.starts_with("test@test_pack_01-v0.1.0"),
"Unexpected filename: {}",
filename
);
remove_test_dir(dir_context.current_dir())?;
Ok(())
}
fn verify_aipack_file(aipack_path: &SPath) -> Result<()> {
assert!(
aipack_path.exists(),
"The .aipack file was not created at {}",
aipack_path
);
assert_eq!(aipack_path.ext(), "aipack", "The file does not have .aipack extension");
let metadata = fs::metadata(aipack_path.path())?;
assert!(
metadata.len() > 100,
"The .aipack file is too small: {} bytes",
metadata.len()
);
Ok(())
}