-
Notifications
You must be signed in to change notification settings - Fork 72
test: add test cases for filename conflicts and existing target directories #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1f19aab
f50848a
eaafa73
b8075a8
5997b24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -94,3 +94,108 @@ async fn test_clone_empty_repo() { | |||
| _ => panic!("should be branch"), | ||||
| }; | ||||
| } | ||||
|
|
||||
| #[tokio::test] | ||||
| #[serial] | ||||
| #[ignore] | ||||
| /// Test the clone command with an existing empty directory | ||||
| async fn test_clone_to_existing_empty_dir() { | ||||
| let temp_path = tempdir().unwrap(); | ||||
| let _guard = test::ChangeDirGuard::new(temp_path.path()); | ||||
| let repo_path = temp_path.path().join("mega-libra-clone-branch-test"); | ||||
| std::fs::create_dir(&repo_path).unwrap(); | ||||
|
|
||||
| let remote_url = "https://gitee.com/pikady/mega-libra-clone-branch-test.git".to_string(); | ||||
|
|
||||
| command::clone::execute(CloneArgs { | ||||
| remote_repo: remote_url, | ||||
| local_path: Some(repo_path.to_str().unwrap().to_string()), | ||||
| branch: Some("dev".to_string()), | ||||
| }) | ||||
| .await; | ||||
|
|
||||
| // Verify that the `.libra` directory exists | ||||
| let libra_dir = repo_path.join(".libra"); | ||||
| assert!(libra_dir.exists()); | ||||
|
|
||||
| // Verify the Head reference | ||||
| match Head::current().await { | ||||
| Head::Branch(current_branch) => { | ||||
| assert_eq!(current_branch, "dev"); | ||||
| } | ||||
| _ => panic!("should be branch"), | ||||
| }; | ||||
| } | ||||
|
|
||||
| #[tokio::test] | ||||
| #[serial] | ||||
| #[ignore] | ||||
| /// Test that clone fails when the target directory exists and is not empty | ||||
| async fn test_clone_to_existing_dir() { | ||||
| let temp_path = tempdir().unwrap(); | ||||
| let _guard = test::ChangeDirGuard::new(temp_path.path()); | ||||
|
|
||||
| let repo_path = temp_path.path().join("mega-libra-clone-branch-test"); | ||||
| std::fs::create_dir(&repo_path).unwrap(); | ||||
| let dummy_file = repo_path.join("exists.txt"); | ||||
| std::fs::write(&dummy_file, "test").unwrap(); | ||||
|
|
||||
| let remote_url = "https://gitee.com/pikady/mega-libra-clone-branch-test.git".to_string(); | ||||
|
|
||||
| command::clone::execute(CloneArgs { | ||||
| remote_repo: remote_url, | ||||
| local_path: Some(repo_path.to_str().unwrap().to_string()), | ||||
| branch: Some("dev".to_string()), | ||||
| }) | ||||
| .await; | ||||
|
|
||||
| // Verify that the `.libra` directory does not exist | ||||
| let libra_dir = repo_path.join(".libra"); | ||||
| assert!(!libra_dir.exists()); | ||||
| // Make sure that the pre-existing file should still exist | ||||
| assert!(dummy_file.exists(), "pre-existing file should still exist"); | ||||
| let content = std::fs::read_to_string(&dummy_file).unwrap(); | ||||
| // Make sure that the pre-existing file content should remain unchanged | ||||
|
||||
| assert_eq!( | ||||
| content, "test", | ||||
| "pre-existing file content should remain unchanged" | ||||
| ); | ||||
| } | ||||
|
|
||||
| #[tokio::test] | ||||
| #[serial] | ||||
| #[ignore] | ||||
| /// Test that clone fails when a file exists at the target path. | ||||
| async fn test_clone_to_dir_with_existing_file_name() { | ||||
| let temp_path = tempdir().unwrap(); | ||||
| let _guard = test::ChangeDirGuard::new(temp_path.path()); | ||||
|
|
||||
| let conflict_path = temp_path.path().join("mega-libra-clone-branch-test"); | ||||
| std::fs::write(&conflict_path, "test").unwrap(); | ||||
|
|
||||
| let remote_url = "https://gitee.com/pikady/mega-libra-clone-branch-test.git".to_string(); | ||||
tianzeshi-study marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
|
||||
| command::clone::execute(CloneArgs { | ||||
| remote_repo: remote_url, | ||||
| local_path: Some(conflict_path.to_str().unwrap().to_string()), | ||||
| branch: Some("dev".to_string()), | ||||
| }) | ||||
| .await; | ||||
tianzeshi-study marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
|
||||
| // Verify that the pre-existing file remains a file (clone should not succeed) | ||||
| assert!( | ||||
| conflict_path.is_file(), | ||||
| "pre-existing file should remain a file" | ||||
| ); | ||||
| // Make sure that the pre-existing file should still exist | ||||
|
||||
| // Make sure that the pre-existing file should still exist |
Uh oh!
There was an error while loading. Please reload this page.