diff --git a/src/entrances/install.rs b/src/entrances/install.rs index f29853f3..ff3b13d8 100644 --- a/src/entrances/install.rs +++ b/src/entrances/install.rs @@ -367,7 +367,7 @@ fn test_install_with_matcher() { // 启动文件服务器 let (_, mut handler) = crate::utils::test::_run_static_file_server(); - // 打包出一个 VSCode_1.85.1.0_Cno + // 打包出一个 VSCode_1.75.4.2_Cno let static_path = Path::new("test/static"); if !static_path.exists() { std::fs::create_dir_all(static_path).unwrap(); @@ -376,7 +376,7 @@ fn test_install_with_matcher() { &"./examples/VSCode".to_string(), Some( static_path - .join("VSCode_1.85.1.0_Cno.nep") + .join("VSCode_1.75.4.2_Cno.nep") .to_string_lossy() .to_string(), ), @@ -414,7 +414,7 @@ fn test_install_with_matcher() { &"./test/VSCode".to_string(), Some( static_path - .join("VSCode_1.85.1.0_Cno.nep") + .join("VSCode_1.75.4.2_Cno.nep") .to_string_lossy() .to_string(), ), @@ -428,7 +428,7 @@ fn test_install_with_matcher() { name: "vscode".to_string(), scope: Some("microsoFT".to_string()), mirror: Some("mock-server".to_string()), - version_req: Some(VersionReq::parse("^1.81").unwrap()), + version_req: Some(VersionReq::parse("^1.75").unwrap()), }, false, ) diff --git a/src/entrances/mirror.rs b/src/entrances/mirror.rs index 7f8937a9..25d96409 100644 --- a/src/entrances/mirror.rs +++ b/src/entrances/mirror.rs @@ -194,7 +194,7 @@ fn test_mirror() { vec![crate::types::mirror::SearchResult { name: "VSCode".to_string(), scope: "Microsoft".to_string(), - version: "1.85.1.0".to_string(), + version: "1.75.4.2".to_string(), from_mirror: Some("mock-server".to_string()), }] ); diff --git a/src/entrances/update.rs b/src/entrances/update.rs index c9f22d4f..d1071b49 100644 --- a/src/entrances/update.rs +++ b/src/entrances/update.rs @@ -300,3 +300,66 @@ fn test_update_using_package() { // 卸载 crate::uninstall(None, &"VSCode".to_string()).unwrap(); } + +#[test] +fn test_update_all() { + let tup = crate::utils::test::_mount_custom_mirror(); + let (_, mut handler) = crate::utils::test::_run_static_file_server(); + envmnt::set("DEBUG", "true"); + envmnt::set("CONFIRM", "true"); + crate::utils::test::_ensure_clear_test_dir(); + + // 确保已卸载 + crate::utils::test::_ensure_testing_vscode_uninstalled(); + crate::utils::test::_ensure_testing_uninstalled("Microsoft", "Notepad"); + + // 生成旧的 Notepad 包 + crate::utils::fs::copy_dir("examples/Notepad", "test/Notepad").unwrap(); + crate::utils::test::_modify_installed_package_version("test/Notepad", "22.0.0.0"); + + // 安装旧版本 + install_using_package(&"examples/VSCode".to_string(), false).unwrap(); + install_using_package(&"test/Notepad".to_string(), false).unwrap(); + + // 生成新包 + crate::utils::fs::copy_dir("examples/VSCode", "test/VSCode").unwrap(); + crate::utils::test::_modify_installed_package_version("test/VSCode", "1.75.4.2"); + crate::pack( + &"./test/VSCode".to_string(), + Some("./test/VSCode_1.75.4.2_Cno.nep".to_string()), + false, + ) + .unwrap(); + crate::pack( + &"./examples/Notepad".to_string(), + Some("./test/Notepad_22.1.0.0_Cno.nep".to_string()), + false, + ) + .unwrap(); + + // 更新全部 + let (_, failure_count) = update_all(false).unwrap(); + assert_eq!(failure_count, 0); + assert!( + info_local(&"Microsoft".to_string(), &"VSCode".to_string()) + .unwrap() + .1 + .version + == *"1.75.4.2" + ); + assert!( + info_local(&"Microsoft".to_string(), &"Notepad".to_string()) + .unwrap() + .1 + .version + == *"22.1.0.0" + ); + + // 卸载 + crate::utils::test::_ensure_testing_vscode_uninstalled(); + crate::utils::test::_ensure_testing_uninstalled("Microsoft", "Notepad"); + + // 清理测试服务器 + handler.kill().unwrap(); + crate::utils::test::_unmount_custom_mirror(tup); +} diff --git a/src/utils/test.rs b/src/utils/test.rs index bbd6256f..08c40108 100644 --- a/src/utils/test.rs +++ b/src/utils/test.rs @@ -108,8 +108,8 @@ pub fn _run_mirror_mock_server() -> String { "name": "VSCode", "releases": [ { - "file_name": "VSCode_1.85.1.0_Cno.nep", - "version": "1.85.1.0", + "file_name": "VSCode_1.75.4.2_Cno.nep", + "version": "1.75.4.2", "size": 94245376, "timestamp": 1704554724 }