mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
refactor: 升级依赖版本并优化构建系统
- 升级核心依赖 (axum 0.8, tower-http 0.6, alsa 0.11 等) - 简化交叉编译配置,切换至 Debian 11 提高兼容性 - 新增 Debian 包打包支持 (debuerreotype 模板) - 移除独立的 mjpeg 解码器,简化视频模块 - 静态链接 libx264/libx265/libopus 到二进制
This commit is contained in:
@@ -507,10 +507,83 @@ impl Drop for ChannelWriter {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::process::Command;
|
||||
use std::sync::OnceLock;
|
||||
use tempfile::TempDir;
|
||||
|
||||
/// Path to ventoy resources directory
|
||||
static RESOURCE_DIR: &str = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../ventoy-img-rs/resources"
|
||||
);
|
||||
|
||||
/// Initialize ventoy resources once
|
||||
fn init_ventoy_resources() -> bool {
|
||||
static INIT: OnceLock<bool> = OnceLock::new();
|
||||
*INIT.get_or_init(|| {
|
||||
let resource_path = std::path::Path::new(RESOURCE_DIR);
|
||||
|
||||
// Decompress xz files if needed
|
||||
let core_xz = resource_path.join("core.img.xz");
|
||||
let core_img = resource_path.join("core.img");
|
||||
if core_xz.exists() && !core_img.exists() {
|
||||
if let Err(e) = decompress_xz(&core_xz, &core_img) {
|
||||
eprintln!("Failed to decompress core.img.xz: {}", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let disk_xz = resource_path.join("ventoy.disk.img.xz");
|
||||
let disk_img = resource_path.join("ventoy.disk.img");
|
||||
if disk_xz.exists() && !disk_img.exists() {
|
||||
if let Err(e) = decompress_xz(&disk_xz, &disk_img) {
|
||||
eprintln!("Failed to decompress ventoy.disk.img.xz: {}", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize resources
|
||||
if let Err(e) = ventoy_img::resources::init_resources(resource_path) {
|
||||
eprintln!("Failed to init ventoy resources: {}", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
})
|
||||
}
|
||||
|
||||
/// Decompress xz file using system command
|
||||
fn decompress_xz(src: &std::path::Path, dst: &std::path::Path) -> std::io::Result<()> {
|
||||
let output = Command::new("xz")
|
||||
.args(&["-d", "-k", "-c", src.to_str().unwrap()])
|
||||
.output()?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("xz decompress failed: {}", String::from_utf8_lossy(&output.stderr)),
|
||||
));
|
||||
}
|
||||
|
||||
std::fs::write(dst, &output.stdout)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ensure resources are initialized, skip test if failed
|
||||
fn ensure_resources() -> bool {
|
||||
if !init_ventoy_resources() {
|
||||
eprintln!("Skipping test: ventoy resources not available");
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_drive_init() {
|
||||
if !ensure_resources() {
|
||||
return;
|
||||
}
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let drive_path = temp_dir.path().join("test_ventoy.img");
|
||||
let drive = VentoyDrive::new(drive_path);
|
||||
@@ -522,6 +595,9 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_drive_mkdir() {
|
||||
if !ensure_resources() {
|
||||
return;
|
||||
}
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let drive_path = temp_dir.path().join("test_ventoy.img");
|
||||
let drive = VentoyDrive::new(drive_path);
|
||||
@@ -537,6 +613,9 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_drive_file_write_and_read() {
|
||||
if !ensure_resources() {
|
||||
return;
|
||||
}
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let drive_path = temp_dir.path().join("test_ventoy.img");
|
||||
let drive = VentoyDrive::new(drive_path.clone());
|
||||
@@ -565,6 +644,9 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_drive_get_file_info() {
|
||||
if !ensure_resources() {
|
||||
return;
|
||||
}
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let drive_path = temp_dir.path().join("test_ventoy.img");
|
||||
let drive = VentoyDrive::new(drive_path.clone());
|
||||
@@ -611,6 +693,9 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_drive_stream_read() {
|
||||
if !ensure_resources() {
|
||||
return;
|
||||
}
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let drive_path = temp_dir.path().join("test_ventoy.img");
|
||||
let drive = VentoyDrive::new(drive_path.clone());
|
||||
@@ -652,6 +737,9 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_drive_stream_read_small_file() {
|
||||
if !ensure_resources() {
|
||||
return;
|
||||
}
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let drive_path = temp_dir.path().join("test_ventoy.img");
|
||||
let drive = VentoyDrive::new(drive_path.clone());
|
||||
|
||||
Reference in New Issue
Block a user