Skip to content

Commit

Permalink
wip: 更新镜像mock
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnotech committed Aug 5, 2024
1 parent c7c6c4a commit 8e8164f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/entrances/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(),
),
Expand Down Expand Up @@ -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(),
),
Expand All @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion src/entrances/mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}]
);
Expand Down
63 changes: 63 additions & 0 deletions src/entrances/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/utils/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8e8164f

Please sign in to comment.