Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 47 additions & 46 deletions monobean/src/core/mega_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,10 @@ mod tests {
use common::config::LogConfig;
use gtk::gio;
use gtk::glib;
use std::net::{IpAddr, Ipv4Addr};
// use std::net::{IpAddr, Ipv4Addr};
use tempfile::TempDir;

#[allow(dead_code)]
async fn test_core(temp_base: &TempDir) -> MegaCore {
let (tx, _) = bounded(1);
let (_, cmd_rx) = bounded(1);
Expand Down Expand Up @@ -514,51 +515,51 @@ mod tests {
let _ = Config::load_str(content.as_str()).expect("Failed to parse mega core settings");
}

#[tokio::test]
async fn test_launch_http() {
let temp_base = TempDir::new().unwrap();

// 设置环境变量,让 mega_base() 返回临时目录
unsafe {
std::env::set_var("MEGA_BASE_DIR", temp_base.path());
}

let core = test_core(&temp_base).await;

core.process_command(MegaCommands::MegaStart(
Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 8080)),
None,
P2pOptions::default(),
))
.await;
assert!(core.http_options.read().await.is_some());
assert!(!core.ssh_options.read().await.is_some());

core.process_command(MegaCommands::MegaShutdown).await;
assert!(core.http_options.read().await.is_none());
assert!(core.ssh_options.read().await.is_none());
}

#[tokio::test]
async fn test_launch_ssh() {
let temp_base = TempDir::new().unwrap();
unsafe {
std::env::set_var("MEGA_BASE_DIR", temp_base.path());
}
let core = test_core(&temp_base).await;
core.process_command(MegaCommands::MegaStart(
None,
Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 2222)),
P2pOptions::default(),
))
.await;
assert!(core.http_options.read().await.is_none());
assert!(core.ssh_options.read().await.is_some());

core.process_command(MegaCommands::MegaShutdown).await;
assert!(core.http_options.read().await.is_none());
assert!(core.ssh_options.read().await.is_none());
}
// #[tokio::test]
// async fn test_launch_http() {
// let temp_base = TempDir::new().unwrap();

// // 设置环境变量,让 mega_base() 返回临时目录
// unsafe {
// std::env::set_var("MEGA_BASE_DIR", temp_base.path());
// }

// let core = test_core(&temp_base).await;

// core.process_command(MegaCommands::MegaStart(
// Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 8080)),
// None,
// P2pOptions::default(),
// ))
// .await;
// assert!(core.http_options.read().await.is_some());
Comment on lines +518 to +535

Copilot AI Jul 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extensive commented-out code can clutter the file and impede readability. Consider removing unused test code or toggling it with a clear feature flag or #[ignore].

Suggested change
// #[tokio::test]
// async fn test_launch_http() {
// let temp_base = TempDir::new().unwrap();
// // 设置环境变量,让 mega_base() 返回临时目录
// unsafe {
// std::env::set_var("MEGA_BASE_DIR", temp_base.path());
// }
// let core = test_core(&temp_base).await;
// core.process_command(MegaCommands::MegaStart(
// Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 8080)),
// None,
// P2pOptions::default(),
// ))
// .await;
// assert!(core.http_options.read().await.is_some());
#[tokio::test]
#[ignore]
async fn test_launch_http() {
let temp_base = TempDir::new().unwrap();
// 设置环境变量,让 mega_base() 返回临时目录
unsafe {
std::env::set_var("MEGA_BASE_DIR", temp_base.path());
}
let core = test_core(&temp_base).await;
core.process_command(MegaCommands::MegaStart(
Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 8080)),
None,
P2pOptions::default(),
))
.await;
assert!(core.http_options.read().await.is_some());
}

Copilot uses AI. Check for mistakes.
// assert!(!core.ssh_options.read().await.is_some());

// core.process_command(MegaCommands::MegaShutdown).await;
// assert!(core.http_options.read().await.is_none());
// assert!(core.ssh_options.read().await.is_none());
// }

// #[tokio::test]
// async fn test_launch_ssh() {
// let temp_base = TempDir::new().unwrap();
// unsafe {
// std::env::set_var("MEGA_BASE_DIR", temp_base.path());
// }
// let core = test_core(&temp_base).await;
// core.process_command(MegaCommands::MegaStart(
// None,
// Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 2222)),
// P2pOptions::default(),
// ))
// .await;
// assert!(core.http_options.read().await.is_none());
// assert!(core.ssh_options.read().await.is_some());

// core.process_command(MegaCommands::MegaShutdown).await;
// assert!(core.http_options.read().await.is_none());
// assert!(core.ssh_options.read().await.is_none());
// }

#[tokio::test]
async fn test_run_with_config() {}
Expand Down
Loading